tea.logger Module

Logging module.

This logging module is designed as a wrapper around the python logging module.

When the module is loaded it configure the logging object with some default parameters (log to stderr with DEBUG level). After that, user can call the L{configure_logger} function and configure logging to file and stderr.

Usage

>>> import logging
>>> import tempfile
>>> from tea.logger import configure_logging
>>> configure_logging(filename=tempfile.mktemp())
>>> logger = logging.getLogger('test')
>>> logger.debug('Debug level log entry')
>>> logger.info('Info level log entry')
>>> logger.warning('Warn level log entry')
WARNING     - Warn level log entry [test:1]
>>> logger.error('Error level log entry')
ERROR       - Error level log entry [test:1]
>>> logger.critical('Critical level log entry')
CRITICAL    - Critical level log entry [test:1]
>>> try:
...     raise Exception('Test exception')
... except Exception:
...     logger.exception('Error level log entry with stack trace')
ERROR       - Error level log entry with stack trace [test:4]
Traceback (most recent call last):
  ...
Exception: Test exception
tea.logger.configure_logging(filename=None, filemode='a', datefmt='%Y.%m.%d %H:%M:%S', fmt='%(asctime)s.%(msecs)03d %(levelname)11s: %(message)s [%(name)s:%(lineno)d]', stdout_fmt='%(levelname)-11s - %(message)s [%(name)s:%(lineno)d]', level=10, stdout_level=30, initial_file_message='', max_size=1048576, rotations_number=5, remove_handlers=True)[source]

Configure logging module.

Parameters:
  • filename (str) – Specifies a filename to log to.
  • filemode (str) – Specifies the mode to open the log file. Values: 'a', 'w'. Default: a.
  • datefmt (str) – Use the specified date/time format.
  • fmt (str) – Format string for the file handler.
  • stdout_fmt (str) – Format string for the stdout handler.
  • level (int) – Log level for the file handler. Log levels are the same as the log levels from the standard logging module. Default: logging.DEBUG
  • stdout_level (int) – Log level for the stdout handler. Log levels are the same as the log levels from the standard logging module. Default: logging.WARNING
  • initial_file_message (str) – First log entry written in file.
  • max_size (int) – Maximal size of the logfile. If the size of the file exceed the maximal size it will be rotated.
  • rotations_number (int) – Number of rotations to save.
  • remove_handlers (bool) – Remove all existing handlers.
tea.logger.log.configure_logging(filename=None, filemode='a', datefmt='%Y.%m.%d %H:%M:%S', fmt='%(asctime)s.%(msecs)03d %(levelname)11s: %(message)s [%(name)s:%(lineno)d]', stdout_fmt='%(levelname)-11s - %(message)s [%(name)s:%(lineno)d]', level=10, stdout_level=30, initial_file_message='', max_size=1048576, rotations_number=5, remove_handlers=True)[source]

Configure logging module.

Parameters:
  • filename (str) – Specifies a filename to log to.
  • filemode (str) – Specifies the mode to open the log file. Values: 'a', 'w'. Default: a.
  • datefmt (str) – Use the specified date/time format.
  • fmt (str) – Format string for the file handler.
  • stdout_fmt (str) – Format string for the stdout handler.
  • level (int) – Log level for the file handler. Log levels are the same as the log levels from the standard logging module. Default: logging.DEBUG
  • stdout_level (int) – Log level for the stdout handler. Log levels are the same as the log levels from the standard logging module. Default: logging.WARNING
  • initial_file_message (str) – First log entry written in file.
  • max_size (int) – Maximal size of the logfile. If the size of the file exceed the maximal size it will be rotated.
  • rotations_number (int) – Number of rotations to save.
  • remove_handlers (bool) – Remove all existing handlers.