log0 package¶
Submodules¶
log0.log0 module¶
Module contents¶
This helper provides a versatile yet easy to use and beautiful logging setup. You can use it to log to the console and optionally to a logfile.
The formatter is heavily inspired by the Tornado web framework, licensed under the Apache 2.0 license.
The call logger.info(“hello”) prints log messages in this format:
[I 170213 15:02:00 test:203] hello
Usage:
from logger import setup_logger
logger = setup_logger() logger.info(“message”)
In order to also log to a file, just add a logfile parameter:
logger = setup_logger(logfile=”/tmp/test.log”)
The default loglevel is logging.DEBUG. You can set it with the parameter level.
-
class
log0.
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={40: 1, 10: 4, 20: 2, 30: 3})[source]¶ Bases:
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.
-
DEFAULT_COLORS
= {40: 1, 10: 4, 20: 2, 30: 3}¶
-
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'¶
-