Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between logging.info and logging.getLogger().info?

Tags:

python

logging

I am a fresh man of python.

If logging.info() is enough for logging, why we have to instantiate a logger with getLogger() method?

like image 489
tidy Avatar asked Jun 27 '12 12:06

tidy


People also ask

What is the difference between logger info and Logger error?

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.

What is the use of logging getLogger?

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 info in Python?

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.

What does logger info do?

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.


1 Answers

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.

like image 127
icecrime Avatar answered Oct 22 '22 00:10

icecrime