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

Question:

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

Asked By: tidy

||

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.

Answered By: icecrime
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.