On this page
  1. logging.setLoggerClass
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

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

REPL Inspect

from logging import setLoggerClass
help(setLoggerClass)

Linked from

Related notes