comparison src/core/log.py @ 992:f51a1895275c

core (log): twisted backend use logging methods instead of log.msg
author Goffi <goffi@goffi.org>
date Sat, 19 Apr 2014 16:48:26 +0200
parents 05e02f8b7eb4
children 652c01ca69b1
comparison
equal deleted inserted replaced
991:05e02f8b7eb4 992:f51a1895275c
94 fmt = s 94 fmt = s
95 s = ''.join(fmt) 95 s = ''.join(fmt)
96 96
97 return s 97 return s
98 98
99
100 root_logger = logging.getLogger() 99 root_logger = logging.getLogger()
101 if len(root_logger.handlers) == 0: 100 if len(root_logger.handlers) == 0:
102 hdlr = logging.StreamHandler() 101 hdlr = logging.StreamHandler()
103 formatter = SatFormatter(FORMAT) 102 formatter = SatFormatter(FORMAT)
104 hdlr.setFormatter(formatter) 103 hdlr.setFormatter(formatter)
117 global _backend 116 global _backend
118 if _backend is not None: 117 if _backend is not None:
119 raise exceptions.InternalError("Logging can only be configured once") 118 raise exceptions.InternalError("Logging can only be configured once")
120 _backend = backend 119 _backend = backend
121 120
122 if backend == C.LOG_BACKEND_TWISTED: 121 if backend in (C.LOG_BACKEND_TWISTED, C.LOG_BACKEND_STANDARD):
123 from twisted.python import log 122 if backend == C.LOG_BACKEND_TWISTED:
124 import logging 123 from twisted.python import log
125 _configureStdLogging(logging, colors=True) 124 observer = log.PythonLoggingObserver()
126 def logMsg(self, msg, level): 125 observer.start()
127 log.msg(msg.encode('utf-8'), logLevel=level)
128 Logger.logMsg = logMsg
129 Logger.debug = lambda self, msg: self.logMsg(msg, logging.DEBUG)
130 Logger.info = lambda self, msg: self.logMsg(msg, logging.INFO)
131 Logger.warning = lambda self, msg: self.logMsg(msg, logging.WARNING)
132 Logger.error = lambda self, msg: self.logMsg(msg, logging.ERROR)
133 Logger.critical = lambda self, msg: self.logMsg(msg, logging.CRITICAL)
134 observer = log.PythonLoggingObserver()
135 observer.start()
136
137 elif backend == C.LOG_BACKEND_STANDARD:
138 global getLogger 126 global getLogger
139 global debug 127 global debug
140 global info 128 global info
141 global warning 129 global warning
142 global error 130 global error