mlpy.tools.log.LoggingMgr

class mlpy.tools.log.LoggingMgr[source]

Bases: object

The logging manager Singleton class.

The logger manager can be included as a member to any class to manager logging of information. Each logger is identified by the module id (mid), with which the logger settings can be changed.

By default a logger with log level LOG_INFO that is output to the stdout is created.

See also

logging

Examples

>>> from mlpy.tools.log import LoggingMgr
>>> logger = LoggingMgr().get_logger('my_id')
>>> logger.info('This is a useful information.')

This gets a new logger. If a logger with the module id my_id already exists that logger will be returned, otherwise a logger with the default settings is created.

>>> LoggingMgr().add_handler('my_id', htype=LoggingMgr.LOG_TYPE_FILE)

This adds a new handler for the logger with module id my_id writing the logs to a file.

>>> LoggingMgr().remove_handler('my_id', htype=LoggingMgr.LOG_TYPE_STREAM)

This removes the stream handler from the logger with module id my_id.

>>> LoggingMgr().change_level('my_id', LoggingMgr.LOG_TYPE_ALL, LoggingMgr.LOG_DEBUG)

This changes the log level for all attached handlers of the logger identified by my_id to LOG_DEBUG.

Attributes

LOG_TYPE_STREAM=0 Log only to output stream (stdout).
LOG_TYPE_FILE=1 Log only to an output file.
LOG_TYPE_ALL=2 Log to both output stream (stdout) and file.
LOG_DEBUG=10 Detailed information, typically of interest only when diagnosing problems.
LOG_INFO=20 Confirmation that things are working as expected.
LOG_WARNING=30 An indication that something unexpected happened, or indicative of some problem in the near future. The software is still working as expected.
LOG_ERROR=40 Due to a more serious problem, the software has not been able to perform some function.
LOG_CRITICAL=50 A serious error, indicating that the problem itself may be unable to continue running.

Methods

add_handler(mid[, htype, hlevel, fmt, filename]) Add a handler to the logger.
change_level(mid, hlevel[, htype]) Set the log level for a handler.
get_logger(mid[, level, htype, fmt, ...]) Get the logger instance with the identified mid.
get_verbosity(mid) Gets the verbosity.
remove_handler(mid, htype) Remove handlers.
set_verbosity(mid, value) Sets the verbosity.