If logging.info()
is enough for logging, why we have to instantiate a logger with getLogger()
method?
What is the difference between logging.info and logging.getLogger().info?
Asked Answered
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.
© 2022 - 2024 — McMap. All rights reserved.
%(module)s
in your log format, then you don't need getLogger to identify the module. – Grainger