@andy_slac and I have recently made a couple of changes to how lsst.log
works.
Firstly, CmdLineTask
and PipelineTask
now register a handler with the root Python logging
logger to ensure that Python logging messages (such as those created by daf_butler
and astro_metadata_translator
) are now forwarded to the lsst.log
system and will be part of the integrated log output. This has been a long term goal and means that for pure Python packages you can use logging
and the messages will turn up in the correct place.
Secondly, it has historically been difficult to write unit tests that check that a log message has been issued. Today I merged a fix for that so that you can forward Python lsst.log
messages to the Python logging
system so that they can be caught.
The easiest way to do this is with:
with self.assertLogs(level="WARNING"):
with lsst.log.UsePythonLogging():
lsst.log.warn("A lsst warning message")
You can turn on this forwarding for an entire test by calling lsst.log.usePythonLogging()
in setUp
and lsst.log.doNotUsePythonLogging()
in tearDown
.
Unfortunately this only works for log messages issued from Python code and we do not have a log4cxx handler that forwards C++ log messages to Python. It was felt that this partial solution is better than no solution at all.