2.3.19. vacumm.misc.log
– Logging utilities¶
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.
-
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)¶
-
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>¶
-
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.
-
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
-
initial_level
= 20¶
-
instances
= <_weakrefset.WeakSet object>¶
-
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_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]¶
-
removeHandler
(hdlr)¶
-
setLevel
(level, filter=False)¶
-
classmethod
set_default_colorize
(active=None)¶
-
-
class
LoggerAdapter
(**kwargs)[source]¶ Bases:
logging.LoggerAdapter
-
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.
-