Module: check_mk
Branch: master
Commit: cda2feb8e5a3f7e0d517a92acb4473230992d4b4
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=cda2feb8e5a3f7…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Jun 22 18:04:45 2017 +0200
Centralized standard log formater in cmk.log
Change-Id: If5ad46f563025a460d66ed5e26bf91341b3ac49c
---
lib/log.py | 6 ++++++
web/htdocs/log.py | 7 +++----
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/lib/log.py b/lib/log.py
index 3fabfb3..ec3c961 100644
--- a/lib/log.py
+++ b/lib/log.py
@@ -80,6 +80,12 @@ def get_logger(name):
return logger.getChild(name)
+def get_formatter():
+ """Returns a new message formater instance that uses the standard
+ Check_MK log format"""
+ return _logging.Formatter("%(asctime)s [%(levelno)s] [%(name)s %(process)d]
%(message)s")
+
+
def setup_console_logging():
"""This method enables all log messages to be written to the console
without any additional information like date/time, logger-name. Just
diff --git a/web/htdocs/log.py b/web/htdocs/log.py
index d9d8f76..a7cc0b2 100644
--- a/web/htdocs/log.py
+++ b/web/htdocs/log.py
@@ -25,9 +25,10 @@
# Boston, MA 02110-1301 USA.
import logging as _logging
+import cmk.log
import cmk.paths
-logger = _logging.getLogger("cmk.web")
+logger = cmk.log.get_logger("web")
def init_logging():
_setup_web_log_logging()
@@ -37,9 +38,7 @@ def _setup_web_log_logging():
handler = _logging.FileHandler("%s/web.log" % cmk.paths.log_dir,
encoding="UTF-8")
- formatter = _logging.Formatter("%(asctime)s [%(levelno)s] [%(name)s %(process)d]
%(message)s")
- handler.setFormatter(formatter)
-
+ handler.setFormatter(cmk.log.get_formatter())
logger.addHandler(handler)