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¶
- class pymor.core.logger.ColoredFormatter[source]¶
Bases:
logging.FormatterA logging.Formatter that colors loglevel keyword output.
Coloring can be disabled by setting the
PYMOR_COLORS_DISABLEenvironment variable to1.Methods
Format the specified record as text.
- format(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.
- class pymor.core.logger.PyMORLogger(name, level=NOTSET)[source]¶
Bases:
logging.LoggerInstances of the Logger class represent a single logging channel. A “logging channel” indicates an area of an application. Exactly how an “area” is defined is up to the application developer. Since an application can have any number of areas, logging channels are identified by a unique string. Application areas can be nested (e.g. an area of “input processing” might include sub-areas “read CSV files”, “read XLS files” and “read Gnumeric files”). To cater for this natural nesting, channel names are organized into a namespace hierarchy where levels are separated by periods, much like the Java or Python package namespace. So in the instance given above, channel names might be “input” for the upper level, and “input.csv”, “input.xls” and “input.gnu” for the sub-levels. There is no arbitrary limit to the depth of nesting.
- block(msg: str, *args, **kwargs) LogIndenter[source]¶
- class pymor.core.logger.RichAwareHandler(level=NOTSET)[source]¶
Bases:
logging.HandlerHandler instances dispatch logging events to specific destinations.
The base handler class. Acts as a placeholder which defines the Handler interface. Handlers can optionally use Formatter instances to format records as desired. By default, no formatter is specified; in this case, the ‘raw’ message as determined by record.message is logged.
Methods
Do whatever it takes to actually log the specified logging record.
- pymor.core.logger.getLogger(module, level=None, filename=None) PyMORLogger[source]¶
Get the logger of the respective module for pyMOR’s logging facility.
In addition to the logging methods inherited from
Loggerall returned loggers get a block, info2, info3 method for the respective new levels. Plus all warnings methods get aXXX_oncemethod 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 (seesetLevel).filename – If not empty, path of an existing file where everything logged will be written to.
- 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
- 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 withwith logger.block(...).block_timings – If
True, measure the duration of a code block started withwith logger.block(...).
- 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 (seesetLevel).