On this page
logging.getLogger
Prev: logging.getLevelNamesMapping | Up: logging | Next: logging.getLoggerClass
Rel: logging.addLevelName, logging.basicConfig, logging.BufferingFormatter, logging.captureWarnings
Ref: docs.python.org — logging.getLogger
Tags: #public #python3 #stdlib #logging
Import
import logging
from logging import getLogger
Signature & Overview
logging.getLogger(name=None)
Return a logger with the specified name, creating it if necessary.
Usage
import logging
pkg = logging.getLogger("pkg")
a = logging.getLogger("pkg.mod")
b = logging.getLogger("pkg.mod")
assert a is b and a.parent is pkg
Gotchas
- Singleton per name: Calling
getLogger(__name__)in every module builds a clean dotted hierarchy matching your package structure. - No arguments returns the root logger:
logging.getLogger()is the root logger.
REPL Inspect
from logging import getLogger
help(getLogger)
Linked from
Related notes
- tuts/python3/stdlib_module/logging/getLevelNamesMapping Linked here; links to this page; shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging/getLoggerClass Linked here; links to this page; shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/logging/addLevelName Linked here; shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging/basicConfig Linked here; shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging/BufferingFormatter Linked here; shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging/captureWarnings Linked here; shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging/critical shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging/debug shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging/disable shared tags: #logging, #stdlib