From d8ba2e7662119ef7720846b133cc506a28dd3964 Mon Sep 17 00:00:00 2001 From: Frank Becker Date: Sun, 9 Feb 2020 11:38:40 +0100 Subject: [PATCH] add basic filebased logging configuration --- bot.py | 11 ++++++++--- config/logging.config | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 config/logging.config diff --git a/bot.py b/bot.py index 65851c0..099c228 100755 --- a/bot.py +++ b/bot.py @@ -10,6 +10,7 @@ import sys import traceback import urllib.parse import logging +import logging.config from importlib import reload import requests @@ -46,14 +47,18 @@ class Bot: self.logger.debug("Initialized") def initializeLogger(self): - log_format = '%(levelname)s - %(name)s - %(message)s' + + if os.path.exists('config/logging.config'): + logging.config.fileConfig('config/logging.config') + else: + log_format = '%(levelname)s - %(name)s - %(message)s' + logging.basicConfig(format=log_format) + if self.debug: logging.root.setLevel(logging.DEBUG) else: logging.root.setLevel(logging.INFO) - logging.basicConfig(format=log_format) - async def send_text(self, room, body): msg = { "body": body, diff --git a/config/logging.config b/config/logging.config new file mode 100644 index 0000000..481e743 --- /dev/null +++ b/config/logging.config @@ -0,0 +1,28 @@ +[loggers] +keys=root,hemppa + +[handlers] +keys=console + +[formatters] +keys=hemppa + +[logger_root] +level=INFO +handlers=console + +[logger_hemppa] +level=NOTSET +handlers= +propagate=1 +qualname=hemppa + +[handler_console] +class=StreamHandler +level=NOTSET +formatter=hemppa +args=(sys.stdout,) + +[formatter_hemppa] +format=%(levelname)s - %(name)s - %(message)s +class=logging.Formatter