Logging

A utility wraps Python built-in loggings

class bigflow.util.log.LogFormatter(color=True, fmt='%(color)s[%(levelname)1.1s %(asctime)s %(module)s:%(lineno)d]%(end_color)s %(message)s', datefmt='%y%m%d %H:%M:%S', colors=None)

基类:logging.Formatter

Log formatter used in Tornado.

Key features of this formatter are:

  • Color support when logging to a terminal that supports it.
  • Timestamps on every log line.
  • Robust against str/bytes encoding problems.

This formatter is enabled automatically by tornado.options.parse_command_line (unless --logging=none is used).

DEFAULT_COLORS = {10: 4, 20: 2, 30: 3, 40: 1}
DEFAULT_DATE_FORMAT = '%y%m%d %H:%M:%S'
DEFAULT_FORMAT = '%(color)s[%(levelname)1.1s %(asctime)s %(module)s:%(lineno)d]%(end_color)s %(message)s'
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.

bigflow.util.log.enable_pretty_logging(logger, level, log_file='', backupCount=10, maxBytes=10000000)

Turns on formatted logging output as configured.

bigflow.util.log.enable_pretty_logging_at_debug(logger, level, log_file='', backupCount=10, maxBytes=10000000)

Turns on formatted logging output only at DEBUG level

bigflow.util.log.init_log(level=20)

init_log - initialize log module

参数:

level (str) --

msg above the level will be displayed DEBUG < INFO < WARNING < ERROR < CRITICAL

the default value is logging.INFO

Raises:
  • OSError -- fail to create log directories
  • IOError -- fail to open log file