cement.ext.ext_logging

Cement logging extension module.

class cement.ext.ext_logging.LoggingLogHandler(*args, **kw)[source]

Bases: cement.core.log.LogHandler

This class is an implementation of the Log interface, and sets up the logging facility using the standard Python logging module.

class Meta[source]

Bases: object

Handler meta-data.

clear_loggers = []

List of logger namespaces to clear. Useful when imported software also sets up logging and you end up with duplicate log entries.

Changes in Cement 2.1.3. Previous versions only supported clear_loggers as a boolean, but did fully support clearing non-app logging namespaces.

config_defaults = {'file': None, 'level': 'INFO', 'max_bytes': 512000, 'max_files': 4, 'rotate': False, 'to_console': True}

The default configuration dictionary to populate the log section.

console_format = '%(levelname)s: %(message)s'

The logging format for the consoler logger.

debug_format = '%(asctime)s (%(levelname)s) %(namespace)s : %(message)s'

The logging format for both file and console if debug==True.

file_format = '%(asctime)s (%(levelname)s) %(namespace)s : %(message)s'

The logging format for the file logger.

formatter_class

alias of logging.Formatter

label = 'logging'

The string identifier of this handler.

log_level_argument = None

List of arguments to use for the cli options (ex: [-l, --list]). If a log-level argument is not wanted, set to None (default).

log_level_argument_help = 'logging level'

The help description for the log level argument

namespace = None

The logging namespace.

Note: Although Meta.namespace defaults to None, Cement will set this to the application label (App.Meta.label) if not set during setup.

_setup(app_obj)[source]

Called during application initialization and must setup the handler object making it ready for the framework or the application to make further calls to it.

Parameters:app (instance) – The application object.
_setup_console_log()[source]

Add a console log handler.

_setup_file_log()[source]

Add a file log handler.

clear_loggers(namespace)[source]

Clear any previously configured loggers for namespace.

debug(msg, namespace=None, **kw)[source]

Log to the DEBUG facility.

Parameters:msg (str) – The message to log.
Keyword Arguments:
 namespace (str) – A log prefix, generally the module __name__ that the log is coming from. Will default to self._meta.namespace if none is passed.
Other Parameters:
 kwargs – Keyword arguments are passed on to the backend logging system.
error(msg, namespace=None, **kw)[source]

Log to the ERROR facility.

Args:msg (str): The message to log.
Keyword Arguments:
 namespace (str) – A log prefix, generally the module __name__ that the log is coming from. Will default to self._meta.namespace if none is passed.
Other Parameters:
 kwargs – Keyword arguments are passed on to the backend logging system.
fatal(msg, namespace=None, **kw)[source]

Log to the FATAL (aka CRITICAL) facility.

Parameters:msg (str) – The message to log.
Keyword Arguments:
 namespace (str) – A log prefix, generally the module __name__ that the log is coming from. Will default to self._meta.namespace if none is passed.
Other Parameters:
 kwargs – Keyword arguments are passed on to the backend logging system.
get_level()[source]

Returns the current log level.

info(msg, namespace=None, **kw)[source]

Log to the INFO facility.

Parameters:msg (str) – The message to log.
Keyword Arguments:
 namespace (str) – A log prefix, generally the module __name__ that the log is coming from. Will default to self._meta.namespace if none is passed.
Other Parameters:
 kwargs – Keyword arguments are passed on to the backend logging system.
set_level(level)[source]

Set the log level. Must be one of the log levels configured in self.levels which are ['INFO', 'WARNING', 'ERROR', 'DEBUG', 'FATAL'].

Parameters:level – The log level to set.
warning(msg, namespace=None, **kw)[source]

Log to the WARNING facility.

Parameters:msg (str) – The message to log.
Keyword Arguments:
 namespace (str) – A log prefix, generally the module __name__ that the log is coming from. Will default to self._meta.namespace if none is passed.
Other Parameters:
 kwargs – Keyword arguments are passed on to the backend logging system.