[Add]新增用于实现单例模式的VtSingleton类,修改LogEngine的单例模式实现
This commit is contained in:
parent
65bc568888
commit
d006349fc3
@ -9,7 +9,7 @@
|
||||
"darkStyle": true,
|
||||
"language": "chinese",
|
||||
|
||||
"logActive": false,
|
||||
"logActive": true,
|
||||
"logLevel": "debug",
|
||||
"logConsole": true,
|
||||
"logFile": true,
|
||||
|
@ -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):
|
||||
|
@ -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]
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user