29 from lsst.utils
import continueClass
43 self.
_log(Log.TRACE,
False, fmt, *args)
46 self.
_log(Log.DEBUG,
False, fmt, *args)
48 def info(self, fmt, *args):
49 self.
_log(Log.INFO,
False, fmt, *args)
51 def warn(self, fmt, *args):
52 self.
_log(Log.WARN,
False, fmt, *args)
55 self.
_log(Log.ERROR,
False, fmt, *args)
58 self.
_log(Log.FATAL,
False, fmt, *args)
60 def tracef(self, fmt, *args, **kwargs):
61 self.
_log(Log.TRACE,
True, fmt, *args, **kwargs)
63 def debugf(self, fmt, *args, **kwargs):
64 self.
_log(Log.DEBUG,
True, fmt, *args, **kwargs)
66 def infof(self, fmt, *args, **kwargs):
67 self.
_log(Log.INFO,
True, fmt, *args, **kwargs)
69 def warnf(self, fmt, *args, **kwargs):
70 self.
_log(Log.WARN,
True, fmt, *args, **kwargs)
72 def errorf(self, fmt, *args, **kwargs):
73 self.
_log(Log.ERROR,
True, fmt, *args, **kwargs)
75 def fatalf(self, fmt, *args, **kwargs):
76 self.
_log(Log.FATAL,
True, fmt, *args, **kwargs)
78 def _log(self, level, use_format, fmt, *args, **kwargs):
79 if self.isEnabledFor(level):
80 frame = inspect.currentframe().f_back
82 filename = os.path.split(frame.f_code.co_filename)[1]
83 funcname = inspect.stack()[2][3]
85 msg = fmt.format(*args, **kwargs)
if args
or kwargs
else fmt
87 msg = fmt % args
if args
else fmt
88 self.logMsg(level, filename, funcname, frame.f_lineno, msg)
99 Log.configure_prop(properties)
103 return Log.getDefaultLoggerName()
107 Log.pushContext(name)
115 Log.MDC(key, str(value))
123 Log.MDCRegisterInit(func)
127 Log.getLogger(loggername).
setLevel(level)
131 Log.getLogger(loggername).
getLevel()
138 def log(loggername, level, fmt, *args, **kwargs):
139 Log.getLogger(loggername)._log(level,
False, fmt, *args)
143 Log.getDefaultLogger()._log(TRACE,
False, fmt, *args)
147 Log.getDefaultLogger()._log(DEBUG,
False, fmt, *args)
151 Log.getDefaultLogger()._log(INFO,
False, fmt, *args)
155 Log.getDefaultLogger()._log(WARN,
False, fmt, *args)
159 Log.getDefaultLogger()._log(ERROR,
False, fmt, *args)
163 Log.getDefaultLogger()._log(FATAL,
False, fmt, *args)
166 def logf(loggername, level, fmt, *args, **kwargs):
167 Log.getLogger(loggername)._log(level,
True, fmt, *args, **kwargs)
171 Log.getDefaultLogger()._log(TRACE,
True, fmt, *args, **kwargs)
175 Log.getDefaultLogger()._log(DEBUG,
True, fmt, *args, **kwargs)
179 Log.getDefaultLogger()._log(INFO,
True, fmt, *args, **kwargs)
183 Log.getDefaultLogger()._log(WARN,
True, fmt, *args, **kwargs)
187 Log.getDefaultLogger()._log(ERROR,
True, fmt, *args, **kwargs)
191 Log.getDefaultLogger()._log(FATAL,
True, fmt, *args, **kwargs)
199 """Context manager for logging."""
216 if self.
name is not None:
217 Log.pushContext(self.
name)
218 if self.
level is not None:
222 if self.
name is not None:
227 Log.getDefaultLogger().
setLevel(level)
230 return Log.getDefaultLogger().
getLevel()
237 """Handler for Python logging module that emits to LSST logging."""
242 logging.Handler.__init__(self)
251 logging.Handler.close(self)
254 if self.context.isEnabledFor(self.
translateLevel(record.levelno)):
255 logging.Handler.handle(self, record)
258 Log.getLogger(record.name).logMsg(self.
translateLevel(record.levelno),
259 record.filename, record.funcName,
261 record.msg % record.args)
265 Translates from standard python logging module levels
266 to standard log4cxx levels.