Details
-
Type:
Story
-
Status: Done
-
Resolution: Done
-
Fix Version/s: None
-
Component/s: log
-
Labels:None
-
Story Points:2
-
Team:Architecture
Description
When writing unit tests it is sometimes useful to check that a log message was created. Python provides TestCase.assertLogs for this purpose but this does not work with lsst.log. It would be useful to allow unit tests to temporarily forward lsst.log messages to Python logging so that they could be tested.
This would have to ensure that DM-15201 does not cause a logging loop.
Ideally C++ log4cxx messages could be forwarded but it seems much easier to focus on Python lsst.log messages.
Andy Salnikov I've rewritten the PR a bit since you looked at it on Friday. I realized that I do not need to raise an exception if forwarding is enabled and the LogHandler is used. All I really need to do is return immediately and let other Handlers work. I have attempted to do a check to see if other handlers will trigger and if I don't find any I send to standard output. Sometimes this leads to messages disappearing since I think a handler has been specified but nothing happens. The advice should probably be that if you are turning on log forwarding for testing that you should also add an explicit StreamHandler to the Python root logger. If you do that everything works fine.