pymor.core.logger

This module contains pyMOR’s logging facilities.

pyMOR’s logging facilities are based on the logging module of the Python standard library. To obtain a new logger object use getLogger. Logging can be configured via the set_log_format and set_log_levels methods.

Module Contents

Classes

ColoredFormatter

A logging.Formatter that inserts tty control characters to color

DummyLogger

LogIndenter

Functions

default_handler

getLogger

Get the logger of the respective module for pyMOR's logging facility.

set_log_levels

Set log levels for pyMOR's logging facility.

set_log_format

Set log levels for pyMOR's logging facility.

_block

_info2

_info3

log_levels

Change levels for given loggers on entry and reset to before state on exit.

Attributes

BLOCK

BLOCK_TIME

INFO2

INFO3

RESET_SEQ

COLOR_SEQ

BOLD_SEQ

COLORS

CSSCOLORS

MAX_HIERARCHY_LEVEL

BLOCK_TIMINGS

INDENT_BLOCKS

INDENT

LAST_TIMESTAMP_LENGTH

start_time

dummy_logger

pymor.core.logger.BLOCK[source]
pymor.core.logger.BLOCK_TIME[source]
pymor.core.logger.INFO2[source]
pymor.core.logger.INFO3[source]
pymor.core.logger.RESET_SEQ = [source]
pymor.core.logger.COLOR_SEQ = [1;%dm[source]
pymor.core.logger.BOLD_SEQ = [source]
pymor.core.logger.COLORS[source]
pymor.core.logger.CSSCOLORS[source]
pymor.core.logger.MAX_HIERARCHY_LEVEL = 1[source]
pymor.core.logger.BLOCK_TIMINGS = True[source]
pymor.core.logger.INDENT_BLOCKS = True[source]
pymor.core.logger.INDENT = 0[source]
pymor.core.logger.LAST_TIMESTAMP_LENGTH = 0[source]
pymor.core.logger.start_time[source]
class pymor.core.logger.ColoredFormatter[source]

Bases: logging.Formatter

A logging.Formatter that inserts tty control characters to color loglevel keyword output. Coloring can be disabled by setting the PYMOR_COLORS_DISABLE environment variable to 1.

_format_common(self, record)[source]
format(self, record)[source]

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

format_html(self, record)[source]
pymor.core.logger.default_handler(filename='')[source]
pymor.core.logger.getLogger(module, level=None, filename='')[source]

Get the logger of the respective module for pyMOR’s logging facility.

In addition to the logging methods inherited from Logger all returned loggers get a block, info2, info3 method for the respective new levels. Plus all warnings methods get a XXX_once method that caches the msg and only emits the log entry the first time (per logger instance, not globally).

Parameters

module

Name of the module.

level

If set, logger.setLevel(level) is called (see setLevel).

filename

If not empty, path of an existing file where everything logged will be written to.

class pymor.core.logger.DummyLogger[source]
__slots__ = [][source]
propagate = False[source]
debug[source]
info[source]
warn[source]
warning[source]
error[source]
critical[source]
log[source]
exception[source]
nop(self, *args, **kwargs)[source]
isEnabledFor(sefl, lvl)[source]
getEffectiveLevel(self)[source]
getChild(self)[source]
block(self, msg, *args, **kwargs)[source]
info2(self, msg, *args, **kwargs)[source]
info3(self, msg, *args, **kwargs)[source]
pymor.core.logger.dummy_logger[source]
pymor.core.logger.set_log_levels(levels=None)[source]

Set log levels for pyMOR’s logging facility.

Parameters

levels

Dict of log levels. Keys are names of loggers (see logging.getLogger), values are the log levels to set for the loggers of the given names (see setLevel).

pymor.core.logger.set_log_format(max_hierarchy_level=1, indent_blocks=True, block_timings=False)[source]

Set log levels for pyMOR’s logging facility.

Parameters

max_hierarchy_level

The number of components of the loggers name which are printed. (The first component is always stripped, the last component always preserved.)

indent_blocks

If True, indent log messages inside a code block started with with logger.block(...).

block_timings

If True, measure the duration of a code block started with with logger.block(...).

class pymor.core.logger.LogIndenter(logger, doit)[source]
__enter__(self)[source]
__exit__(self, exc_type, exc_val, exc_tb)[source]
pymor.core.logger._block(self, msg, *args, **kwargs)[source]
pymor.core.logger._info2(self, msg, *args, **kwargs)[source]
pymor.core.logger._info3(self, msg, *args, **kwargs)[source]
pymor.core.logger.log_levels(level_mapping)[source]

Change levels for given loggers on entry and reset to before state on exit.

Parameters

level_mapping

a dict of logger name -> level name