Python Forum

Full Version: logging: child module unable to get parent config
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I had some problems with logging
According to The Doc
in the same Python interpreter, you get the same logger object with the same config

But if that's true, why can't my code work
https://gist.github.com/isjerryxiao/b6ff...c011ae7a7a

Actually I was trying to make traceback look prettier in log files.

my test environment:
Python 3.7.3 (default, Mar 26 2019, 21:43:19)
[GCC 8.2.1 20181127] on linux
The calls to logging.getLogger(__name__) create two different logger instances in your code, namely logging.getLogger('__main__') and logging.getLogger('mymodule').
(Apr-08-2019, 04:17 PM)Gribouillis Wrote: [ -> ]The calls to logging.getLogger(__name__) create two different logger instances in your code, namely logging.getLogger('__main__') and logging.getLogger('mymodule').

I don't think so, according to the Python Doc I posted above, calls to the other instances should be passed to the main logger instance, otherwise the example code there shouldn't even work.
Quote:logging.getLogger(name=None)
Return a logger with the specified name or, if name is None, return a logger which is the root logger of the hierarchy. If specified, the name is typically a dot-separated hierarchical name like ‘a’, ‘a.b’ or ‘a.b.c.d’. Choice of these names is entirely up to the developer who is using logging.

All calls to this function with a given name return the same logger instance. This means that logger instances never need to be passed between different parts of an application.


That's clearly documented, but i did not look carefully.