On this page
  1. logging.NullHandler
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

logging.NullHandler

Prev: logging.makeLogRecord | Up: logging | Next: logging.setLoggerClass
Rel: logging.addLevelName, logging.basicConfig, logging.BufferingFormatter, logging.captureWarnings
Ref: docs.python.org — logging.NullHandler
Tags: #public #python3 #stdlib #logging


Import

import logging
from logging import NullHandler

Signature & Overview

logging.NullHandler(level=0)

This handler does nothing. It's intended to be used to avoid the "No handlers could be found for logger XXX" one-off warning. This is important for library code, which may contain code to log events. If a user

Methods & Attributes

Usage

import logging

# Recommended setup in a reusable library's __init__.py
lib_logger = logging.getLogger("mylib")
lib_logger.addHandler(logging.NullHandler())
lib_logger.warning("silent unless the application configures logging")

Gotchas

REPL Inspect

from logging import NullHandler
help(NullHandler)

Linked from

Related notes