From 491f19a9cbecbf89979d1857a0d459db22237aa2 Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Thu, 21 Mar 2024 22:50:22 -0400 Subject: [PATCH] don't include date in logging when running via systemd --- relay/logger.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/relay/logger.py b/relay/logger.py index ca9d76d..b8ff918 100644 --- a/relay/logger.py +++ b/relay/logger.py @@ -63,10 +63,10 @@ def set_level(level: LogLevel | str) -> None: def verbose(message: str, *args: Any, **kwargs: Any) -> None: - if not logging.root.isEnabledFor(LogLevel['VERBOSE']): + if not logging.root.isEnabledFor(LogLevel.VERBOSE): return - logging.log(LogLevel['VERBOSE'], message, *args, **kwargs) + logging.log(LogLevel.VERBOSE, message, *args, **kwargs) debug: Callable = logging.debug @@ -76,8 +76,6 @@ error: Callable = logging.error critical: Callable = logging.critical -env_log_level: Path | str | None = os.environ.get('LOG_LEVEL', 'INFO').upper() - try: env_log_file: Path | None = Path(os.environ['LOG_FILE']).expanduser().resolve() @@ -89,10 +87,16 @@ handlers: list[Any] = [logging.StreamHandler()] if env_log_file: handlers.append(logging.FileHandler(env_log_file)) -logging.addLevelName(LogLevel['VERBOSE'], 'VERBOSE') +if os.environ.get('INVOCATION_ID'): + logging_format = '%(levelname)s: %(message)s' + +else: + logging_format = '[%(asctime)s] %(levelname)s: %(message)s' + +logging.addLevelName(LogLevel.VERBOSE, 'VERBOSE') logging.basicConfig( level = LogLevel.INFO, - format = '[%(asctime)s] %(levelname)s: %(message)s', + format = logging_format, datefmt = '%Y-%m-%d %H:%M:%S', handlers = handlers )