Reference

Module Members

umsg._msg(msg, level=None, prefix=None, logger=None, exc_info=False, stack_info=False, extra=None, end='\n')

Base log message facilitator.

Parameters
  • msg (str) – Message to be logged.

  • level (str or int, optional) – Logging level to use. Logging levels may be provided as either a string literal, or as a standard logging library logging level enum or direct numeric value. Custom levels are not supported. (Default: ‘info’)

  • prefix (str, optional) – Message prefix to apply. This will override any prefix defined in the profile. (Default: profile value).

  • logger (logging.Logger, optional) – Specific logger to send the message to. This will override the logger value defined in the profile. (Default: profile value)

  • exc_info (bool or tuple, optional) – If an exception tuple (in the format returned by sys.exc_info()) or an exception instance is provided, it is used; otherwise, sys.exc_info() is called to get the exception information. (Default: False)

  • stack_info (bool or tuple, optional) – If true, stack information is added to the logging message, including the actual logging call; the same as the standard logging facilities. (Default: False)

  • extra (dict, optional) –

    Dictionary of user-defined attributes. These are generally parameters to the Formatter as would be passed to the standard logging facilities.

  • end (str, optional) – Final character appended to printed messages in Verbose mode only. This is passed to the print() function. (Default: ‘\n’)

umsg.log(msg, level=None, prefix=None, logger=None, exc_info=False, stack_info=False, extra=None, end='\n')

Logs the given message.

Notes

This function is an alias for _msg() in order to provide a PEP8 compliant name.

umsg.init(**kwargs)

Initialize logging based on module profile.

Initialize the logging mechanism based on the current module’s profile settings. If the module profile does not exist, it will first be created with the default values, and then initialized. The logger name will be set to the module name if the value is None. init() accepts all profile attributes as parameters at call time. All values given will be recorded in the profile.

Parameters
  • logger (logging.Logger, optional) – Logger object.

  • logger_name (str, optional) – Logger name.

  • level (str or int, optional) – Logging level to set the logger to.

  • mode (str or int, optional) – Alias for level, provided for compatibility.

  • date_format (str, optional) – Logging date format.

  • msg_format (str, optional) – Logging record message format.

  • msg_prefix (str, optional) – Custom prefix to prepend to logging message string.

  • msg_prefix_format (str, optional) – Custom prefix format string.

  • exc_info (bool, optional) – exc_info setting. If custom exc_info is desired in the form of an exception tuple, this will need to be supplied with the actual log message call. See _msg().

  • stack_info (bool, optional) – stack_info setting.

  • propagate (bool, optional) – Propagate logging.

  • verbose (bool, optional) – Send messages to console instead of the logger.

umsg.add_handler(handler, **kwargs)

Adds a new handler to the module / package logger.

Adds the given handler to the logger using the default formatter. If a custom formatter is required for this handler, it should be added using the native addHandler() method as follows:

get_attr(‘logger’).addHandler(handler)

handler (handler): Handler to add. If an instance is

provided, **kwargs is ignored. If a class reference is provided, **kwargs are passed to initializer.

**kwargs (dict, optional): Dictionary of keyword arguments to the handler.

umsg.get_attr(name)

Get profile logging attribute.

Retrieve the current module’s logging profile attribute specified. If the logging profile does not exist, it will be created with the default values.

Parameters

name (str) – Name of the attribute to retrieve.

Returns

The attribute value or None.

umsg.set_attr(name, value)

Set profile logging attribute.

Set the current module’s logging profile attriube specified to the value given. If the logging profile does not exist, it will first be created with the default values, and then updated.

Parameters
  • name (str) – Name of the attribute to set.

  • value – Value to set the attribute to.

Mixins

class umsg.mixins.LoggingMixin(*args, prefix=None, logger=None, **kwargs)

LoggingMixin provides an interface to the module logging functions.

Class instance level methods for calling the module level logging functions. Two private override attributes are provided for the class.

_umsg_logger

Logger object override.

Type

logging.Logger

_umsg_log_prefix

Log message prefix override

Type

str

_msg(*args, **kwargs)

Inteface for module level umsg._msg() function.

log(*args, **kwargs)

Interface for module level umsg.log() function.

Defaults Profile Values

core.DEFAULT_LOGGER = None
core.DEFAULT_LOGGER_NAME = None
core.DEFAULT_LEVEL = 20
core.DEFAULT_DATE_FORMAT = '%Y-%m-%d %H:%M:%S'
core.DEFAULT_MSG_FORMAT = '%(asctime)s - %(levelname)s - %(message)s'
core.DEFAULT_MSG_PREFIX = None
core.DEFAULT_MSG_PREFIX_FORMAT = '[{prefix}] '
core.DEFAULT_EXC_INFO = False
core.DEFAULT_STACK_INFO = False
core.DEFAULT_PROPAGATE = True
core.DEFAULT_VERBOSE = False