cement.ext.ext_logging

Cement logging extension module.

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

Bases: 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

Class to use as the formatter

alias of 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.

propagate = False

Whether or not to propagate logs up to parents. Likely should always be False, but is here in the off chance this breaks something. Setting to False resolves situations where duplicate logs appear with other libraries who logged to the root logger.

Note, if attempting to use PyTest caplog fixture, this may need to be set to True.

See: tests.ext.test_ext_colorlog.test_colorlog.

_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.

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

Log to the CRITICAL facility.

Parameters:
  • msg (str) – The message to log.

  • kwargs – Keyword arguments are passed on to the backend logging system.

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.

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

Log to the DEBUG facility.

Parameters:
  • msg (str) – The message to log.

  • kwargs – Keyword arguments are passed on to the backend logging system.

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.

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.

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.

As of Cement 3.0.10, this method is deprecated and will be removed in future versions of Cement. Please us critical() instead.

Parameters:
  • msg (str) – The message to log.

  • kwargs – Keyword arguments are passed on to the backend logging system.

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.

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.

  • kwargs – Keyword arguments are passed on to the backend logging system.

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.

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', 'CRITICAL].

As of Cement 3.0.10, the FATAL facility is deprecated and will be removed in future versions of Cement. Please us CRITICAL instead.

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.

  • kwargs – Keyword arguments are passed on to the backend logging system.

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.