enable logger with param

pull/178/head
Nevysha 2023-07-06 21:37:37 +02:00
parent fa5f17ffe6
commit a9bae13427
2 changed files with 24 additions and 9 deletions

18
preload.py Normal file
View File

@ -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",
)

View File

@ -2,16 +2,13 @@ import json
import os import os
from pathlib import Path from pathlib import Path
from modules import shared
def is_log_enabled(): def is_log_enabled():
# check if the file log_enabled exists (in the same folder) if shared.cmd_opts.cozy_nest_debug:
# if it does, then check log_enabled value (as json) return True
try: return False
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
# This is a simple logger class that will be used to log messages stdout # This is a simple logger class that will be used to log messages stdout
@ -36,7 +33,7 @@ class CozyLoggerClass:
CozyLogger = CozyLoggerClass("Cozy") CozyLogger = CozyLoggerClass("Cozy")
if CozyLoggerClass.LOG_ENABLED: if CozyLoggerClass.LOG_ENABLED:
CozyLogger.warning("Logger enabled. delete 'log_enabled' file to disable") CozyLogger.warning("Logger enabled")
CozyLoggerExtNe = CozyLoggerClass("Cozy:ExtNe") CozyLoggerExtNe = CozyLoggerClass("Cozy:ExtNe")
CozyLoggerConfig = CozyLoggerClass("Cozy:Config") CozyLoggerConfig = CozyLoggerClass("Cozy:Config")