-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
parent logger should also check the level #75045
Comments
it will print 'Hello world' |
I will let Vinay answer definitively, but this is working as designed. This allows you to set 'debug' level on a sub-logger without getting debug output for every logger in your system, which is what you would get otherwise as the default logging level is NOTSET. The documentation for setLevel could probably be improved slightly in this regard, as currently you have to infer this behavior from the fact that NOTSET causes the ancestor logger's level to be used, implying that if you set it, that setting is used and not the ancestor logger's level. |
As RDM says, this behaviour is as designed. The logger's setLevel documentation says: "Sets the threshold for this logger to lvl. Logging messages which are less severe than lvl will be ignored. When a logger is created, the level is set to NOTSET (which causes all messages to be processed when the logger is the root logger, or delegation to the parent when the logger is a non-root logger). Note that the root logger is created with level WARNING. The term ‘delegation to the parent’ means that if a logger has a level of NOTSET, its chain of ancestor loggers is traversed until either an ancestor with a level other than NOTSET is found, or the root is reached. If an ancestor is found with a level other than NOTSET, then that ancestor’s level is treated as the effective level of the logger where the ancestor search began, and is used to determine how a logging event is handled. If the root is reached, and it has a level of NOTSET, then all messages will be processed. Otherwise, the root’s level will be used as the effective level." Not sure how I can improve upon that, as it seems clear enough, but any suggestions are welcome. |
yes, I understand the effective level. my question is that before call ancestor's handler, should also check
|
@qingyunha: we are telling you that that would *introduce* a bug. This is working the way it is supposed to. Vinay, what if we rewrote the beginning of that paragraph like this: Sets the threshold for this logger to lvl. Logging messages which are less severe than lvl will be ignored, logging messages which have severity lvl or higher will be emitted by whichever handler or handlers service this logger, unless the handler's level has been set to a higher severity level than lvl. When a logger is created, the level is set to NOTSET.... |
Maybe I misunderstand. At least the basicConfig should also set the level of the handler that it created. |
I think you do misunderstand. The level of the handler created by basicConfig doesn't have any level set, so it will process any message it is asked to handle. This is working as designed. |
Sorry to disturb. When calling |
basicConfig() provides default behaviour for simple cases. If you don't like the defaults it provides, you can choose your own configuration code to do exactly what you want. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: