Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-17651: Allow lsst.log to forward to Python logging #37

Merged
merged 7 commits into from Feb 5, 2019

Conversation

timj
Copy link
Member

@timj timj commented Feb 2, 2019

This only deals with the python messages. C++ log messages will do what they always do. This is implemented as a big class property on lsst.log.Log. The idea is that a test can turn this on in setUp, check that a log message was created, and then turn it off in tearDown.

@timj timj requested a review from andy-slac February 2, 2019 00:12
@timj
Copy link
Member Author

timj commented Feb 2, 2019

@ktlim Would this be an alternative approach to #33? I assume JupyterNotebooks do handle Python logging properly. Although Tasks running inside notebooks will get really confused with this approach.

Copy link
Contributor

@andy-slac andy-slac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK. I'd probably add new method to log module to change that class variable instead of manipulating it directly. Log class is implementation detail and should not be used directly. Also having that method would probably help if we decide to implement log4cxx forwarding too.

@ktlim
Copy link
Contributor

ktlim commented Feb 2, 2019

I don't know what the split is between Python and C++ logging in normal Task output. Having some output may be better than none, but it doesn't seem like a comprehensive-enough solution to replace #33 completely.

Copy link
Contributor

@andy-slac andy-slac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK, though logic is bit more complicated than I expected (my logic is binary 🙂)

@@ -250,6 +328,36 @@ def emit(self, record):
logger = Log.getLogger(record.name)
# Use standard formatting class to format message part of the record
message = self.formatter.format(record)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message is not used when UsePythonLogging is set, maybe move it below if to save few CPU cycles.

python/lsst/log/log/logContinued.py Outdated Show resolved Hide resolved
python/lsst/log/log/logContinued.py Outdated Show resolved Hide resolved
# If the logger has a parent and propagation is allowed
# do nothing.
if pylgr.parent and pylgr.parent.hasHandlers() and pylgr.propagate:
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that in general it is a mistake to have root logger configured without any handlers. So you should probably only handle one special case when this handler is the only handler for the root logger?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean always return immediately unless this is the root logger and no handlers exist?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess this is what it means - standard way to use LogHandler is to setup root logger to only have a LogHandler handler. Attaching LogHandler to non-root loggers is still possible but then people are supposed to know what they are doing and if they disable propagation then we are not expected to send messages to other handlers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave it as is for the moment so that the message might appear. The logic is a bit tricky because if LogHandler is attached to a child logger and also the root logger you have to work through the logic multiple times and try not to duplicate yourself. Always returning without action might be the best approach (and is what happens most of the time).

If Python forwarding is enabled the lsst.log.LogHandler should
do nothing itself and rely on other logging handlers to process
the message.  If no other handlers are present attempts to
use a StreamHandler.
Python logging has deprecating logging.warn and preferrs
logging.warning.  This change adds lsst.log.warning to
enable both forms to reduce cognitive dissonance between
the two logging packages.
@timj timj merged commit 87bceb6 into master Feb 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants