Further upgrades to Logging
This commit is contained in:
parent
c0769ad0b1
commit
5e30c2f7da
@ -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
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from logging.handlers import SysLogHandler
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
class Logger:
|
class Logger:
|
||||||
@ -17,13 +19,39 @@ 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)
|
||||||
|
Loading…
Reference in New Issue
Block a user