35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
import logging
|
|
from logging.handlers import WatchedFileHandler
|
|
import sys
|
|
|
|
FORMATTER = logging.Formatter("%(asctime)s — %(name)s — %(levelname)s — %(message)s")
|
|
|
|
logFileHandler = WatchedFileHandler("geruecht/log/debug.log")
|
|
logFileHandler.setFormatter(FORMATTER)
|
|
|
|
logStreamHandler = logging.StreamHandler(stream=sys.stdout)
|
|
logStreamHandler.setFormatter(FORMATTER)
|
|
|
|
def getLogger(logger_name):
|
|
return getDebugLogger(logger_name)
|
|
|
|
def getInfoLogger(logger_name):
|
|
logger = logging.getLogger(logger_name)
|
|
logger.setLevel(logging.INFO)
|
|
logger.addHandler(logStreamHandler)
|
|
logFileHandler = WatchedFileHandler("geruecht/log/info/{}.log".format(logger_name))
|
|
logFileHandler.setFormatter(FORMATTER)
|
|
logger.addHandler(logFileHandler)
|
|
return logger
|
|
|
|
def getDebugLogger(logger_name, path=False):
|
|
|
|
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 |