logging - loggers and formatters

This module contains list of default log formatter and loggers used by package logging services.

FORMATTERS

Registry of log formatter classes (see ClassRegistry for available methods).

HANDLERS

Registry of log handlers classes (see ClassRegistry for available methods).

class Logger[source]

Main logger class.

info(msg, /, *args, **kws) None[source]

INFO log.

debug(msg, /, *args, **kws) None[source]

DEBUG log.

error(msg, /, *args, **kws) None[source]

ERROR log.

warning(msg, /, *args, **kws) None[source]

WARNING log.

makeRecord(name, level, fn, lno, msg, args, exc_info, func=None, extra=None, sinfo=None)[source]

A factory method which can be overridden in subclasses to create specialized LogRecords.

class TextFormatter[source]

Formatter for human-readable text.

__init__(*args, datefmt: str = default_date_fmt, fmt: str = default_log_fmt, **kws)[source]

Initialize.

Parameters:
  • output_data – output log extra data

  • output_context – output log adapter context data

  • datefmt – log date format

  • fmt – log format

  • limit_var – limit variables in log in symbols

  • args – see logging.Formatter.__init__

  • kws – see logging.Formatter.__init__

class DataFormatter[source]

Colored formatter is used to pretty-print colored text in CLI.

Text color depends on log level.

__init__(*args, debug: bool = False, encoder: str = MimeType.json.value, encoders=ENCODERS, **kws)[source]

Initialize.

Parameters:
  • debug – output debug information about exceptions

  • encoder – data encoding format or encoder object itself or None for no additional encoding

  • encoders – optional encoder classes registry

  • args – see TextFormatter

  • kws – see TextFormatter

format(record)[source]

Format log record.

formatMessage(record) str[source]

Format log message.

formatException(ei)[source]

Format exception (skip it).

create_message(record: _LogRecord) LogMessage[source]

Create log message dict from a log record.

class JSONHandler[source]

JSON log queue handler (better performance).

formatter_cls

alias of DataFormatter

class TextHandler[source]

Human-readable text log queue handler.

formatter_cls

alias of TextFormatter

__init__(app=None, formatter: dict = None, stream: str = None)[source]

Initialize.

Parameters:
  • app – web app

  • formatter – formatter class settings

  • stream – optional stream type ‘stdout’ or ‘stderr’

setFormatter(fmt) None[source]

Set the formatter for this handler.

prepare(record)[source]

Prepare a record for queuing. The object returned by this method is enqueued.

The base implementation formats the record to merge the message and arguments, and removes unpickleable items from the record in-place. Specifically, it overwrites the record’s msg and message attributes with the merged message (obtained by calling the handler’s format method), and sets the args, exc_info and exc_text attributes to None.

You might want to override this method if you want to convert the record to a dict or JSON string, or send a modified copy of the record while leaving the original intact.