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

1

18

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

Appointed answered 27/6, 2012 at 12:8 Comment(0)
C
15

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.

Cricoid answered 27/6, 2012 at 12:13 Comment(1)
If you have %(module)s in your log format, then you don't need getLogger to identify the module.Grainger

© 2022 - 2024 — McMap. All rights reserved.