Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

log.logger

import log

Everything here is re-exported by log, so import log is enough and the names are called as log.*. Importing log.logger on its own works too and reaches the same definitions.

The flat, module-level logging functions (log(), info(), debug(), warn(), error(), critical(), exception()), and Logger: namespaced, structured-field-bound loggers built on top of the exact same dispatch path.

The module is callable. log(...) is the same call as log.log(...), documented below.

Functions

log()

log.log(...args: list)

Logs a message with level [[log.None]] on all registered transports.

The format of the output log is dependent on the specific transport service as well as limitations on the nature and type of arguments that is passed to the function.

Parameters

  • any...

info()

log.info(...args: list)

Logs a message with level [[log.Info]] on all registered transports. The arguments and limitations as same as in [[log.log()]].

Parameters

  • any...

debug()

log.debug(...args: list)

Logs a message with level [[log.Debug]] on all registered transports. The arguments and limitations as same as in [[log.log()]].

Parameters

  • any...

warn()

log.warn(...args: list)

Logs a message with level [[log.Warning]] on all registered transports. The arguments and limitations as same as in [[log.log()]].

Parameters

  • any...

error()

log.error(...args: list)

Logs a message with level [[log.Error]] on all registered transports. The arguments and limitations as same as in [[log.log()]].

Parameters

  • any...

critical()

log.critical(...args: list)

Logs a message with level [[log.Critical]] on all registered transports. The arguments and limitations as same as in [[log.log()]].

Parameters

  • any...

exception()

log.exception(ex, message)

Logs an exception with level [[log.Error]] on all registered transports, including its message and stacktrace.

Parameters

  • ex (any) — Expected to be an Error instance (from a catch block); anything else is logged via its string form instead.
  • message (?any) — Optional additional context to log alongside the exception.

get_logger()

log.get_logger(name: string) -> [[log.Logger]]

Returns a [[log.Logger]] namespaced under the given name. Repeated calls with the same name return the same instance, matching Python’s logging.getLogger(): so binding fields on a logger obtained one place is visible everywhere else that same name is requested.

Parameters

  • name (string)

Returns [[log.Logger]]

Classes

Logger

class log.Logger

A namespaced logger that tags every record it writes with a name and, optionally, a set of bound structured fields. Get one via [[log.get_logger]] rather than constructing directly.

Example
import log

var db_log = log.get_logger('db')
db_log.info('connection established')
# ... [db]: connection established

var pool_log = db_log.child('pool').bind({ pool_size: 10 })
pool_log.warn('pool exhausted')
# ... [db.pool]: pool exhausted pool_size=10

Fields

FieldTypeDescription
name

Constructor

log.Logger(name: string, fields)

Logger.bind()

log.Logger.bind(fields: dict)

Logger.child()

log.Logger.child(sub_name: string)

Logger.info()

log.Logger.info(...args: list)

Logger.debug()

log.Logger.debug(...args: list)

Logger.warn()

log.Logger.warn(...args: list)

Logger.error()

log.Logger.error(...args: list)

Logger.critical()

log.Logger.critical(...args: list)

Logger.exception()

log.Logger.exception(ex, message)