2.3.19. vacumm.misc.log – Logging utilities

2.3.19.1. Overview

Attributes:
  • default
  • hascurses
  • logger
Functions:
Classes:

2.3.19.2. Content

Logging features

class ColoredStreamHandler(stream, *args, **kwargs)[source]

Bases: logging.StreamHandler

colors = {'blackb': 40, 'blackf': 30, 'blueb': 44, 'bluef': 34, 'boldoff': 22, 'boldon': 1, 'cyanb': 46, 'cyanf': 36, 'greenb': 42, 'greenf': 32, 'invoff': 27, 'invon': 7, 'italicsoff': 23, 'italicson': 3, 'purpleb': 45, 'purplef': 35, 'redb': 41, 'redf': 31, 'reset': 0, 'uloff': 24, 'ulon': 4, 'whiteb': 47, 'whitef': 37, 'yellowb': 43, 'yellowf': 33}
format(record)[source]

Format the specified record.

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

get_level_color(level)[source]
level_colors = {0: 'reset', 10: 'cyanf', 15: 'bluef', 20: 'greenf', 25: 'greenf,boldon', 30: 'yellowf,boldon', 40: 'redf,boldon', 50: 'purplef,boldon'}
class Formatter(fmt=None, datefmt=None)[source]

Bases: logging.Formatter

exception LogLevelError(level)[source]

Bases: exceptions.Exception

class Logger(name=None, level=None, format=None, date_format=None, console=True, colorize=True, logfile=None, redirect_warnings=False, redirect_stdout=False, redirect_stderr=False, name_filters=None, config=None)[source]

Bases: logging.Logger

Logger based on the standard python logging package.

addHandler(handler, **kwargs)
classmethod add_argparser_options(*args, **kwargs)[source]
add_handler(handler, **kwargs)[source]
classmethod add_optparser_options(*args, **kwargs)[source]
add_rotating_file_handler(*args, **kwargs)[source]
classmethod add_shared_handler(handler)[source]
add_stream_handler(*args, **kwargs)[source]
apply_argparser_options(*args, **kwargs)[source]
classmethod apply_class_argparser_options(*args, **kwargs)[source]
classmethod apply_class_optparser_options(*args, **kwargs)[source]
apply_optparser_options(*args, **kwargs)[source]
clean()[source]
colorize(active=None)[source]
config(*args, **kwargs)[source]

Get or set logging configuration

This method uses the get_* and set_* methods.

Params:
  • args: depending of the type:
    • basestring: (getter) return the corresponding value(s)
    • Logger: (setter) use this logger’s configuration
    • dict: (setter) use this dict’s configuration
  • kwargs: key/value pairs of configuration which are to be set

Getter:

>>> logger.config('level')
%(default_level)r
>>> logger.config('level', 'format')
(%(default_level)r, %(default_format)r)
>>> logger.config() # return complete configuration as a dict
TODO

Setter:

>>> logger.config(level=%(default_level)r)
>>> logger.config(level=%(default_level)r, format=%(default_format)r)
>>> logger.config(configdict) # use a dict as config key/value pairs
>>> logger.config(otherlogger) # use another logger's configuration
default = <vacumm.misc.log.Logger object>
classmethod default_colorize(active=None)[source]
default_date_format = {'console': '', 'default': '%Y-%m-%d %H:%M:%S %Z', 'logfile': '%Y-%m-%d %H:%M:%S %Z'}
default_encoding = None
default_format = {'console': '[%(name)s %(levelname)s] %(message)s', 'default': '[%(asctime)s %(name)s %(levelname)s] %(message)s', 'logfile': '[%(asctime)s %(name)s %(levelname)s] %(message)s'}
default_level = 20
default_max_file_backup = 0
default_max_file_size = 512000
filter_name(value, default)[source]

Used by the set_{level,format,date_format} instance methods. The logger get_name() and instance variable self.__name_filters are evaluated against the couples name1=value1[,name2=value2,…] in value to determine the value to return, default is returned if nothing match, value is return if it isn’t a filter expression.

findCaller()[source]

Find the stack frame of the caller so that we can note the source file name, line number and function name.

get_date_format()[source]
classmethod get_default_colorize(active=None)
classmethod get_default_date_format(target=None)[source]

Get the default date format for the specified target, or all formats dict if target is None

classmethod get_default_format(target=None)[source]

Get the default format for the specified target, or all formats dict if target is None

classmethod get_default_level()[source]
get_format()[source]
get_level()[source]
get_level_name()[source]
get_name()[source]
get_name_filters()[source]
initial_level = 20
instances = <_weakrefset.WeakSet object>
is_debug()[source]
is_verbose()[source]
load_config(cfgo=None, nested=True)[source]
log(level, msg, *args, **kwargs)[source]

Log ‘msg % args’ with the integer severity ‘level’.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.log(level, “We have a %s”, “mysterious problem”, exc_info=1)

classmethod new_formatter(format=None, date_format=None, formatter=None)[source]
classmethod new_rotating_file_handler(filePath=None, mode='a', maxFileSize=None, maxFileBkp=None, encoding=None, level=None, format=None, date_format=None, **kwargs)[source]
classmethod new_stream_handler(stream=<open file '<stderr>', mode 'w'>, colorize=False, level=None, format=None, date_format=None, **kwargs)[source]
notice(msg, *args, **kwargs)[source]
removeHandler(hdlr)
remove_handler(hdlr)[source]
setLevel(level, filter=False)
set_date_format(format, filter=False)[source]
classmethod set_default_colorize(active=None)
classmethod set_default_date_format(format, target=None, filter=False)[source]
classmethod set_default_format(format, target=None, filter=False)[source]
classmethod set_default_level(level, filter=False)[source]
classmethod set_default_max_file_backup(value, filter=False)[source]
classmethod set_default_max_file_size(value, filter=False)[source]
set_format(format, filter=False)[source]
classmethod set_handler_formats(handler, format=None, date_format=None)[source]
set_level(level, filter=False)[source]
set_level_console(level, filter=False)[source]
set_level_logfile(level, filter=False)[source]
set_name(name)[source]
set_name_filters(filters)[source]
shared_handlers = []
showwarning(message, category, filename, lineno, file=None)[source]
skipCaller(caller=None, skip=True)[source]

Register a function, method, code or set/list/tuple of codes to be skipped by findCaller

start_redirections(which='all')[source]
stop_redirections(which='all')[source]
verbose(msg, *args, **kwargs)[source]
class LoggerAdapter(**kwargs)[source]

Bases: logging.LoggerAdapter

get_logger()[source]
is_debug()[source]

Return True if the logger level is debug (or greater)

is_verbose()[source]

Return True if the logger level is verbose (or greater)

notice(msg, *args, **kwargs)[source]

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

process(msg, kwargs)[source]

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.

verbose(msg, *args, **kwargs)[source]

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

class StreamLogWrapper(stream, logger, name='')[source]

Bases: object

write(s)[source]
check_level(level)[source]
convert_level(level)[source]

Convert a level from int/str to str/int

filter_name(names, value, default)[source]
get_int_level(level)[source]

Get the int level for the given int/str level

get_int_levels()[source]
get_str_level(level)[source]

Get the str level for the given int/str level

get_str_levels()[source]