The bareon.openstack.common.log Module

OpenStack logging handler.

This module adds to logging functionality by adding the option to specify a context object when calling the various log methods. If the context object is not specified, default formatting is used. Additionally, an instance uuid may be passed as part of the log message, which is intended to make it easier for admins to find messages related to a specific instance.

It also allows setting of formatting information through conf.

class bareon.openstack.common.log.BaseLoggerAdapter(logger, extra)

Bases: logging.LoggerAdapter

audit(msg, *args, **kwargs)
class bareon.openstack.common.log.ColorHandler(stream=None)

Bases: logging.StreamHandler

LEVEL_COLORS = {10: '\x1b[00;32m', 20: '\x1b[00;36m', 21: '\x1b[01;36m', 30: '\x1b[01;33m', 40: '\x1b[01;31m', 50: '\x1b[01;31m'}
format(record)

Format the specified record.

If a formatter is set, use it. Otherwise, use the default formatter for the module.

class bareon.openstack.common.log.ContextAdapter(logger, project_name, version_string)

Bases: bareon.openstack.common.log.BaseLoggerAdapter

deprecated(msg, *args, **kwargs)

Call this method when a deprecated feature is used.

If the system is configured for fatal deprecations then the message is logged at the ‘critical’ level and DeprecatedConfig will be raised.

Otherwise, the message will be logged (once) at the ‘warn’ level.

Raises:DeprecatedConfig if the system is configured for fatal deprecations.
handlers
process(msg, kwargs)

Process the logging message and keyword arguments passed in to a logging call to insert contextual information. You can either manipulate the message itself, the keyword args or both. Return the message and kwargs modified (or not) to suit your needs.

Normally, you’ll only need to override this one method in a LoggerAdapter subclass for your specific needs.

warn(msg, *args, **kwargs)

Delegate a warning call to the underlying logger, after adding contextual information from this adapter instance.

class bareon.openstack.common.log.ContextFormatter(*args, **kwargs)

Bases: logging.Formatter

A context.RequestContext aware formatter configured through flags.

The flags used to set format strings are: logging_context_format_string and logging_default_format_string. You can also specify logging_debug_format_suffix to append extra formatting if the log level is debug.

For information about what variables are available for the formatter see: http://docs.python.org/library/logging.html#formatter

If available, uses the context value stored in TLS - local.store.context

format(record)

Uses contextstring if request_id is set, otherwise default.

formatException(exc_info, record=None)

Format exception output with CONF.logging_exception_prefix.

exception bareon.openstack.common.log.DeprecatedConfig(msg)

Bases: exceptions.Exception

message = u'Fatal call to deprecated config: %(msg)s'
class bareon.openstack.common.log.JSONFormatter(fmt=None, datefmt=None)

Bases: logging.Formatter

format(record)

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.

formatException(ei, strip_newlines=True)

Format and return the specified exception information as a string.

This default implementation just uses traceback.print_exception()

class bareon.openstack.common.log.LazyAdapter(name='unknown', version='unknown')

Bases: bareon.openstack.common.log.BaseLoggerAdapter

logger
exception bareon.openstack.common.log.LogConfigError(log_config, err_msg)

Bases: exceptions.Exception

message = u'Error loading logging config %(log_config)s: %(err_msg)s'
class bareon.openstack.common.log.RFCSysLogHandler(*args, **kwargs)

Bases: logging.handlers.SysLogHandler

format(record)

Format the specified record.

If a formatter is set, use it. Otherwise, use the default formatter for the module.

class bareon.openstack.common.log.WritableLogger(logger, level=20)

Bases: object

A thin wrapper that responds to write and logs.

write(msg)
bareon.openstack.common.log.getLazyLogger(name='unknown', version='unknown')

Returns lazy logger.

Creates a pass-through logger that does not create the real logger until it is really needed and delegates all calls to the real logger once it is created.

bareon.openstack.common.log.getLogger(name='unknown', version='unknown')
bareon.openstack.common.log.mask_password(message, secret='***')

Replace password with ‘secret’ in message.

Parameters:
  • message – The string which includes security information.
  • secret – value with which to replace passwords.
Returns:

The unicode value of message with the password fields masked.

For example:

>>> mask_password("'adminPass' : 'aaaaa'")
"'adminPass' : '***'"
>>> mask_password("'admin_pass' : 'aaaaa'")
"'admin_pass' : '***'"
>>> mask_password('"password" : "aaaaa"')
'"password" : "***"'
>>> mask_password("'original_password' : 'aaaaa'")
"'original_password' : '***'"
>>> mask_password("u'original_password' :   u'aaaaa'")
"u'original_password' :   u'***'"
bareon.openstack.common.log.set_defaults(logging_context_format_string)
bareon.openstack.common.log.setup(product_name, version='unknown')

Setup logging.