logger

Implement different type of loggers.

loggerFactory.logger.get_logger_by_name(name=None, rand_name=False, charset='0123456789abcdef')[source]

Get a logger by name.

Parameters
  • name – None / str, logger name.

  • rand_name – if True, name will be ignored, a random name will be used.

class loggerFactory.logger.BaseLogger(name=None, rand_name=False, **kwargs)[source]

A base class for logger constructor.

debug(msg, indent=0, **kwargs)[source]

invoke self.logger.debug

info(msg, indent=0, **kwargs)[source]

invoke self.info.debug

warning(msg, indent=0, **kwargs)[source]

invoke self.logger.warning

error(msg, indent=0, **kwargs)[source]

invoke self.logger.error

critical(msg, indent=0, **kwargs)[source]

invoke self.logger.critical

show(msg, indent=0, style='', **kwargs)[source]

Print message to console, indent format may apply.

remove_all_handler()[source]

Unlink the file handler association.

recover_all_handler()[source]

Relink the file handler association you just removed.

class loggerFactory.logger.StreamOnlyLogger(name=None, rand_name=False, stream_level=20, stream_format='%(message)s')[source]

This logger only print message to console, and not write log to files.

Parameters
  • stream_level – level above this will be streamed.

  • stream_format – log information format.

中文文档

只将日志打印到控制台, 并不将日志信息写入到文件。

class loggerFactory.logger.SingleFileLogger(name=None, rand_name=False, path=None, logging_level=10, stream_level=20, logging_format='%(asctime)s; %(levelname)-8s; %(message)s', stream_format='%(message)s', reset=False)[source]

This logger print message to console and also write log to files.

Only one log file will be used.

Parameters
  • path (str) – the absolute path to the log file

  • reset (bool) – if True, the old log content will be removed.

中文文档

日志被写入到单个文件中。

class loggerFactory.logger.FileRotatingLogger(name=None, rand_name=False, path=None, logging_level=10, stream_level=20, logging_format='%(asctime)s; %(levelname)-8s; %(message)s', stream_format='%(message)s', max_bytes=1000000000, backup_count=10)[source]

Definition:

https://docs.python.org/2/library/logging.handlers.html#rotatingfilehandler

Parameters
  • path – the absolute path to the log file

  • max_bytes – max file size.

  • backup_count – max number of files.

中文文档

当日志文件的体积大于某个阈值时, 自动重名名, 将日志录入到新的文件中。

class loggerFactory.logger.TimeRotatingLogger(name=None, rand_name=False, path=None, logging_level=10, stream_level=20, logging_format='%(asctime)s; %(levelname)-8s; %(message)s', stream_format='%(message)s', rotate_on_when='D', interval=1, backup_count=30)[source]

Definition:

https://docs.python.org/2/library/logging.handlers.html#timedrotatingfilehandler

Parameters
  • rotate_on_when – could be “h” (hour), “D” (Day).

  • interval – rotate on how many hour/day.

  • backup_count – max number of files.

中文文档

根据日志发生的时间, 每隔一定时间就更换一个文件名。