Should not it be handled by a single import? i.e. import logging. If I do not include import logging.config in my script, it gives :
AttributeError: 'module' object has no attribute 'config'
It is used by most of the third-party Python libraries, so you can integrate your log messages with the ones from those libraries to produce a homogeneous log for your application. With the logging module imported, you can use something called a “logger” to log messages that you want to see.
The logging configuration functionality tries to offer convenience, and in part this is done by offering the ability to convert text in configuration files into Python objects used in logging configuration - for example, as described in User-defined objects.
The config() method of a Logger class used to Log an config message. This method is used to pass config types logs to all the registered output Handler objects. Config Level: Configuration Information may be like what CPU the application is running on, how much is the disk and memory space.
The getLogger() function accepts a single argument - the logger's name. It returns a reference to a logger instance with the specified name if provided, or root if not. Multiple calls to getLogger() with the same name will return a reference to the same logger object.
logging
is a package. Modules in packages aren't imported until you (or something in your program) imports them. You don't need both import logging
and import logging.config
though: just import logging.config
will make the name logging
available already.
Just add an addtional explanation for Thomas's answer.
logging
is a package, a directory.
enter the logging dir and list what files there is:
config.py handlers.py __init__.py __pycache__
so, There is a config.py
file in logging directory, but why it can't import logging.config
. That's because there is no config
namespace in logging/__init__.py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With