On this page
logging.setLoggerClass
Prev: logging.NullHandler | Up: logging | Next: logging.setLogRecordFactory
Rel: logging.addLevelName, logging.basicConfig, logging.BufferingFormatter, logging.captureWarnings
Ref: docs.python.org — logging.setLoggerClass
Tags: #public #python3 #stdlib #logging
Import
import logging
from logging import setLoggerClass
Signature & Overview
logging.setLoggerClass(klass)
Set the class to be used when instantiating a logger. The class should define init() such that only a name argument is required, and the init() should call Logger.init()
Usage
import logging
class CustomLogger(logging.Logger):
pass
old_cls = logging.getLoggerClass()
logging.setLoggerClass(CustomLogger)
try:
assert isinstance(logging.getLogger("demo.custom_cls_unique"), CustomLogger)
finally:
logging.setLoggerClass(old_cls)
Gotchas
- Only affects newly created loggers: Loggers already instantiated via
getLogger()beforesetLoggerClass()keep their old class.
REPL Inspect
from logging import setLoggerClass
help(setLoggerClass)
Linked from
Related notes
- tuts/python3/stdlib_module/logging/NullHandler Linked here; links to this page; shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging/setLogRecordFactory 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