diff --git a/examples/CtaTrading/VT_setting.json b/examples/CtaTrading/VT_setting.json index b5b81f40..a00ff35e 100644 --- a/examples/CtaTrading/VT_setting.json +++ b/examples/CtaTrading/VT_setting.json @@ -9,7 +9,7 @@ "darkStyle": true, "language": "chinese", - "logActive": false, + "logActive": true, "logLevel": "debug", "logConsole": true, "logFile": true, diff --git a/vnpy/trader/vtEngine.py b/vnpy/trader/vtEngine.py index 1d717795..58181d83 100644 --- a/vnpy/trader/vtEngine.py +++ b/vnpy/trader/vtEngine.py @@ -538,22 +538,15 @@ class DataEngine(object): class LogEngine(object): """日志引擎""" + # 单例模式 + __metaclass__ = VtSingleton + # 日志级别 LEVEL_DEBUG = logging.DEBUG LEVEL_INFO = logging.INFO LEVEL_WARN = logging.WARN LEVEL_ERROR = logging.ERROR LEVEL_CRITICAL = logging.CRITICAL - - # 单例对象 - instance = None - - #---------------------------------------------------------------------- - def __new__(cls, *args, **kwargs): - """创建对象,保证单例""" - if not cls.instance: - cls.instance = super(LogEngine, cls).__new__(cls, *args, **kwargs) - return cls.instance #---------------------------------------------------------------------- def __init__(self): diff --git a/vnpy/trader/vtObject.py b/vnpy/trader/vtObject.py index a0881b7a..2a3a4cb9 100644 --- a/vnpy/trader/vtObject.py +++ b/vnpy/trader/vtObject.py @@ -325,8 +325,23 @@ class VtCancelOrderReq(object): self.orderID = EMPTY_STRING # 报单号 self.frontID = EMPTY_STRING # 前置机号 self.sessionID = EMPTY_STRING # 会话号 - + +######################################################################## +class VtSingleton(type): + """ + 单例,应用方式:静态变量 __metaclass__ = Singleton + """ + + _instances = {} + + #---------------------------------------------------------------------- + def __call__(cls, *args, **kwargs): + """调用""" + if cls not in cls._instances: + cls._instances[cls] = super(VtSingleton, cls).__call__(*args, **kwargs) + + return cls._instances[cls]