Logger

This module implements various logging facilities for the PyGears framework. It is a wrapper around standard Python logging but provides some additional features like:

  • automatic exception raising when logging at any level

  • customized stack trace printing

  • logging to temporary files

  • integration with PyGears registry for configuration

To register a new logger create a CustomLog instance by specifying the logger name and the default logging level:

>>> CustomLog('core', log.WARNING)

Logging Levels

The numeric values of logging levels are given in the following table.

Level

Numeric value

CRITICAL

50

ERROR

40

WARNING

30

INFO

20

DEBUG

10

NOTSET

0

Reference

class register_custom_log

PyGears integrated logger class.

Parameters:
  • name – logger name

  • verbosity – default logging level:

CustomLog instances are customizable via logger/logger_name registry subtree. The logger instance registry subtree contains the following configuration variables:

  • level (int): All messages that are logged with a verbosity level below this configured level value will be discarded. See Logging Levels for a list of levels.

  • print_traceback (bool): If set to True, the traceback will be printed along with the log message.

  • optional level name with desired action. Custom actions can be set for any verbosity level by passing the function or any already supported action to the appropriate registry subtree. Supported actions are:

    • exception: if set, an exception will be raised whenever logging the message at the desired level

    • debug: if set, the debugger will be started and execution paused

    • pass: if set, the message will be printed and no further action taken; this is usefull for clearing prevously set values

Sets the verbosity level for the core logger at INFO level:

>>> reg['logger/core/level'] = INFO

Configures the typing logger to throw exception on warnings:

>>> reg['logger/typing/warning'] = 'exception'

Configures the conf logger to use custom function on errors:

>>> reg['logger/conf/errors'] = custom_func