Further upgrades to Logging

This commit is contained in:
root 2023-03-27 20:12:37 -07:00
parent c0769ad0b1
commit 5e30c2f7da
2 changed files with 31 additions and 4 deletions

View File

@ -22,7 +22,6 @@ import os
# import pprint # import pprint
import shutil import shutil
import sys import sys
import syslog
import time import time
import yaml import yaml

View File

@ -1,5 +1,7 @@
import logging import logging
from logging.handlers import SysLogHandler
import sys import sys
class Logger: class Logger:
@ -17,14 +19,40 @@ class Logger:
self.__logger.setLevel(level) self.__logger.setLevel(level)
formatter = logging.Formatter('[%(asctime)s][%(name)s][%(levelname)s] %(message)s') formatter = logging.Formatter('[%(name)s][%(levelname)s] %(message)s')
formatter_full = logging.Formatter('[%(asctime)s][%(name)s][%(levelname)s] %(message)s')
# Console output / stream handler # Console output / stream handler (STDOUT)
handler = logging.StreamHandler() handler = logging.StreamHandler(
stream=sys.stdout
)
handler.setLevel(level)
handler.addFilter(lambda entry: entry.levelno <= logging.INFO)
handler.setFormatter(formatter_full)
self.__logger.addHandler(handler)
# Console output / stream handler (STDERR)
handler = logging.StreamHandler(
stream=sys.stderr
)
handler.setLevel(logging.WARNING)
handler.setFormatter(formatter_full)
self.__logger.addHandler(handler)
# Syslog handler
handler = SysLogHandler(
address="/dev/log"
)
handler.setLevel(level) handler.setLevel(level)
handler.setFormatter(formatter) handler.setFormatter(formatter)
self.__logger.addHandler(handler) self.__logger.addHandler(handler)
self.debug("Test debug log")
self.info("Test info log")
self.warn("Test warn log")
self.error("Test error log")
def debug(self, s): def debug(self, s):
self.__logger.debug(s) self.__logger.debug(s)
def info(self, s): def info(self, s):