From bd91f06d170b4d822b0254a6e9dd4e13713bc49a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= Date: Fri, 8 Jun 2018 12:18:46 +0200 Subject: [PATCH] log: Introduce log level CONSOLE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This level has the highest severity. It is meant for important messages about situations which may require user intervention. These messages will be shown to the user on the console when running tuned-adm (this is implemented in a followup commit). Signed-off-by: Ondřej Lysoněk --- tuned/consts.py | 3 +++ tuned/logs.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/tuned/consts.py b/tuned/consts.py index d81b69b..00a841c 100644 --- a/tuned/consts.py +++ b/tuned/consts.py @@ -110,3 +110,6 @@ ADMIN_TIMEOUT = 600 # was set automatically or manually ACTIVE_PROFILE_AUTO = "auto" ACTIVE_PROFILE_MANUAL = "manual" + +LOG_LEVEL_CONSOLE = 60 +LOG_LEVEL_CONSOLE_NAME = "CONSOLE" diff --git a/tuned/logs.py b/tuned/logs.py index e3da574..d881b54 100644 --- a/tuned/logs.py +++ b/tuned/logs.py @@ -40,6 +40,9 @@ class TunedLogger(logging.getLoggerClass()): self.setLevel(logging.INFO) self.switch_to_console() + def console(self, msg, *args, **kwargs): + self.log(consts.LOG_LEVEL_CONSOLE, msg, *args, **kwargs) + def switch_to_console(self): self._setup_console_handler() self.remove_all_handlers() @@ -78,5 +81,6 @@ class TunedLogger(logging.getLoggerClass()): filename, maxBytes = consts.LOG_FILE_MAXBYTES, backupCount = consts.LOG_FILE_COUNT) cls._file_handler.setFormatter(cls._formatter) +logging.addLevelName(consts.LOG_LEVEL_CONSOLE, consts.LOG_LEVEL_CONSOLE_NAME) logging.setLoggerClass(TunedLogger) atexit.register(logging.shutdown)