Commit e44a0de6 authored by Robin Obůrka's avatar Robin Obůrka

Refactor logging according to more pythonic way of logging usage

parent 7beabb82
......@@ -2,16 +2,4 @@ from sn.exceptions import *
from sn.messages import *
from sn.argparser import *
from sn.network import *
import logging
import logging.handlers
logging.basicConfig(
level=logging.INFO,
format="sentinel: %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
handlers=[
logging.FileHandler("sentinel.log", encoding="UTF-8"),
logging.handlers.SysLogHandler(address="/dev/log"),
],
)
import sn.logging
import logging
import logging.handlers
formatter = logging.Formatter("sentinel: %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s",
"%Y-%m-%d %H:%M:%S")
time_formatter = logging.Formatter("[%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s",
"%Y-%m-%d %H:%M:%S")
syslog_handler = logging.handlers.SysLogHandler(address="/dev/log")
syslog_handler.setFormatter(formatter)
syslog_handler.setLevel(logging.INFO)
file_handler = logging.handlers.RotatingFileHandler("sentinel.log", maxBytes=10*1024*1024, backupCount=10)
file_handler.setFormatter(time_formatter)
file_handler.setLevel(logging.DEBUG)
root_logger = logging.getLogger()
root_logger.setLevel(logging.DEBUG)
root_logger.addHandler(syslog_handler)
root_logger.addHandler(file_handler)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment