I am a fresh man of python.
If logging.info()
is enough for logging, why we have to instantiate a logger with getLogger()
method?
INFO is used to log the information your program is working as expected. DEBUG is used to find the reason in case your program is not working as expected or an exception has occurred. it's in the interest of the developer.
getLogger(name) is typically executed. 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.
What is logging? Logging is a Python module in the standard library that provides the facility to work with the framework for releasing log messages from the Python programs. Logging is used to tracking events that occur when the software runs. This module is widely used by the developers when they work to logging.
The info() method of a Logger class is used to Log an INFO message. This method is used to forward logs to all the registered output Handler objects. INFO message: Info is for the use of administrators or advanced users.
Calling getLogger()
without a name returns the root logger:
Return a logger with the specified name or, if no name is specified, return a logger which is the root logger of the hierarchy.
Calling the module-level info()
function logs directly to the root logger:
Logs a message with level INFO on the root logger.
If you have no use for specifically named loggers (for example in order to identify the emitting module of the log), the two calls are exactly equivalent.
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