From 4b59b87f98358cec1d6c1451507ddc86e91dd836 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 22 Feb 2018 18:44:00 -0500 Subject: [PATCH] Add convenience methods for all log levels --- piker/log.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/piker/log.py b/piker/log.py index 4d5c4c01..cc7d9771 100644 --- a/piker/log.py +++ b/piker/log.py @@ -1,6 +1,7 @@ """ Log like a forester! """ +from functools import partial import sys import logging import json @@ -51,6 +52,13 @@ def get_logger(name: str = None) -> logging.Logger: if name and name != _proj_name: log = rlog.getChild(name) log.level = rlog.level + + # additional levels + for name, val in LEVELS.items(): + logging.addLevelName(val, name) + # ex. create ``log.trace()`` + setattr(log, name.lower(), partial(log.log, val)) + return log @@ -70,10 +78,6 @@ def get_console_log(level: str = None, name: str = None) -> logging.Logger: ): handler = logging.StreamHandler() - # additional levels - for name, val in LEVELS.items(): - logging.addLevelName(val, name) - formatter = colorlog.ColoredFormatter( LOG_FORMAT, datefmt=DATE_FORMAT,