From a9bae134272f55bc015072c417f218584095241d Mon Sep 17 00:00:00 2001 From: Nevysha Date: Thu, 6 Jul 2023 21:37:37 +0200 Subject: [PATCH] enable logger with param --- preload.py | 18 ++++++++++++++++++ scripts/cozy_lib/CozyLogger.py | 15 ++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 preload.py diff --git a/preload.py b/preload.py new file mode 100644 index 0000000..acf7f6b --- /dev/null +++ b/preload.py @@ -0,0 +1,18 @@ +def preload(parser): + # parser.add_argument( + # "--cozy-nest-session_secret_key", + # type=str, + # help="Secret key for session cookie", + # default=None, + # ) + # parser.add_argument( + # "--cozy-auth", + # type=str, + # help="Comma-separated list of username:password pairs for basic auth", + # default=None, + # ) + parser.add_argument( + "--cozy-nest-debug", + action="store_true", + help="Enable debug logging", + ) diff --git a/scripts/cozy_lib/CozyLogger.py b/scripts/cozy_lib/CozyLogger.py index 5ee585c..6770f57 100644 --- a/scripts/cozy_lib/CozyLogger.py +++ b/scripts/cozy_lib/CozyLogger.py @@ -2,16 +2,13 @@ import json import os from pathlib import Path +from modules import shared + def is_log_enabled(): - # check if the file log_enabled exists (in the same folder) - # if it does, then check log_enabled value (as json) - try: - log_config_file = Path(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'log_enabled')) - if log_config_file.is_file(): - return True - except Exception: - return False + if shared.cmd_opts.cozy_nest_debug: + return True + return False # This is a simple logger class that will be used to log messages stdout @@ -36,7 +33,7 @@ class CozyLoggerClass: CozyLogger = CozyLoggerClass("Cozy") if CozyLoggerClass.LOG_ENABLED: - CozyLogger.warning("Logger enabled. delete 'log_enabled' file to disable") + CozyLogger.warning("Logger enabled") CozyLoggerExtNe = CozyLoggerClass("Cozy:ExtNe") CozyLoggerConfig = CozyLoggerClass("Cozy:Config")