[Add]增加主引擎中注册日志模块对事件监听类型的函数,close #501

This commit is contained in:
vn.py 2017-09-23 14:24:00 +08:00
parent 9778e85480
commit eba153f3da
2 changed files with 13 additions and 2 deletions

View File

@ -80,6 +80,9 @@ class CtaEngine(object):
# 引擎类型为实盘
self.engineType = ENGINETYPE_TRADING
# 注册日式事件类型
self.mainEngine.registerLogEvent(EVENT_CTA_LOG)
# 注册事件监听
self.registerEvent()
@ -335,6 +338,7 @@ class CtaEngine(object):
"""快速发出CTA模块日志事件"""
log = VtLogData()
log.logContent = content
log.gatewayName = 'CTA_STRATEGY'
event = Event(type_=EVENT_CTA_LOG)
event.dict_['data'] = log
self.eventEngine.put(event)

View File

@ -185,6 +185,7 @@ class MainEngine(object):
"""快速发出日志事件"""
log = VtLogData()
log.logContent = content
log.gatewayName = 'MAIN_ENGINE'
event = Event(type_=EVENT_LOG)
event.dict_['data'] = log
self.eventEngine.put(event)
@ -324,7 +325,12 @@ class MainEngine(object):
self.logEngine.addFileHandler()
# 注册事件监听
self.eventEngine.register(EVENT_LOG, self.logEngine.processLogEvent)
self.registerLogEvent(EVENT_LOG)
#----------------------------------------------------------------------
def registerLogEvent(self, eventType):
"""注册日志事件监听"""
self.eventEngine.register(eventType, self.logEngine.processLogEvent)
#----------------------------------------------------------------------
def convertOrderReq(self, req):
@ -593,7 +599,8 @@ class LogEngine(object):
"""处理日志事件"""
log = event.dict_['data']
function = self.levelFunctionDict[log.logLevel] # 获取日志级别对应的处理函数
function(log.logContent)
msg = '\t'.join([log.gatewayName, log.logContent])
function(msg)
########################################################################