Tools for better logging

This module provides

  • a function to a logger configured for logging with color-coded log levels: get_colorlog()

  • a context manager allowing changing log levels per context: Logging

Usage:

>>> from clldutils.loglib import Logging, get_colorlog
>>> log = get_colorlog(__name__)
>>> log.debug('nothing to see')
>>> with Logging(log, level=logging.DEBUG):
...     log.debug('but now')
DEBUG   but now
clldutils.loglib.get_colorlog(name, stream=None, level=20)[source]

Get a logger set up with colorlog’s formatter.

Return type:

logging.Logger

class clldutils.loglib.Logging(logger, level=10)[source]

A context manager to execute a block of code at a specific logging level.