# Logging changes

**URL:** <https://www.rubin.community/t/logging-changes/3580>\
**Category:** DM Notifications\
**Tags:** dm-dev\
**Created:** [February 5, 2019, 6:19pm UTC](https://www.rubin.community/t/logging-changes/3580 "2019-02-05T18:19:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![timj](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/timj/32/10_2.png) [@timj](https://www.rubin.community/u/timj)\
**Post date:** [February 5, 2019, 6:19pm UTC](https://www.rubin.community/t/logging-changes/3580/1 "2019-02-05T18:19:42Z")

</div>

@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:

```python
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.
