flaschengeist/geruecht/logger.py

35 lines
1.2 KiB
Python
Raw Normal View History

import logging
from logging.handlers import WatchedFileHandler
import sys
FORMATTER = logging.Formatter("%(asctime)s%(name)s%(levelname)s%(message)s")
2020-03-09 18:54:51 +00:00
logFileHandler = WatchedFileHandler("geruecht/log/debug.log")
logFileHandler.setFormatter(FORMATTER)
logStreamHandler = logging.StreamHandler(stream=sys.stdout)
logStreamHandler.setFormatter(FORMATTER)
def getLogger(logger_name):
2020-03-09 18:54:51 +00:00
return getDebugLogger(logger_name)
def getInfoLogger(logger_name):
logger = logging.getLogger(logger_name)
2020-03-09 18:54:51 +00:00
logger.setLevel(logging.INFO)
logger.addHandler(logStreamHandler)
2020-03-09 18:54:51 +00:00
logFileHandler = WatchedFileHandler("geruecht/log/info/{}.log".format(logger_name))
logFileHandler.setFormatter(FORMATTER)
logger.addHandler(logFileHandler)
return logger
2020-03-09 18:54:51 +00:00
def getDebugLogger(logger_name, path=False):
2020-03-09 18:54:51 +00:00
logger = logging.getLogger(logger_name)
if path:
logSecondFileHandler = WatchedFileHandler("geruecht/log/debug/{}.log".format(logger_name))
logSecondFileHandler.setFormatter(FORMATTER)
logger.addHandler(logSecondFileHandler)
logger.setLevel(logging.DEBUG)
logger.addHandler(logFileHandler)
logger.propagate = False
return logger