From 1be1c7d8e50c28bfe3f469db10d1f0e900aecd57 Mon Sep 17 00:00:00 2001 From: souvik ghosh Date: Tue, 24 Oct 2023 12:07:26 +0200 Subject: [PATCH] feat: make structlog configurable --- rasa/__main__.py | 2 +- rasa/utils/log_utils.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/rasa/__main__.py b/rasa/__main__.py index 2132e9027c99..856aca5ae8dc 100644 --- a/rasa/__main__.py +++ b/rasa/__main__.py @@ -128,7 +128,7 @@ def main() -> None: endpoints_file=endpoints_file ) # configure structlog - configure_structlog(log_level) + configure_structlog(log_level, logging_config_file) cmdline_arguments.func(cmdline_arguments) elif hasattr(cmdline_arguments, "version"): diff --git a/rasa/utils/log_utils.py b/rasa/utils/log_utils.py index 5852a1ba3e45..7c5d780e53ef 100644 --- a/rasa/utils/log_utils.py +++ b/rasa/utils/log_utils.py @@ -2,13 +2,14 @@ import os import logging import sys -from typing import Any, Dict, Optional +from typing import Any, Dict, Optional, Text import structlog from structlog_sentry import SentryProcessor from structlog.dev import ConsoleRenderer from structlog.typing import EventDict, WrappedLogger from rasa.shared.constants import ENV_LOG_LEVEL, DEFAULT_LOG_LEVEL +from rasa.utils.common import configure_logging_from_file from rasa.plugin import plugin_manager @@ -72,19 +73,22 @@ def _anonymizer( def configure_structlog( log_level: Optional[int] = None, + logging_config_file: Optional[Text] = None, ) -> None: """Configure logging of the server.""" + if logging_config_file is not None: + configure_logging_from_file(logging_config_file) if log_level is None: # Log level NOTSET is 0 so we use `is None` here log_level_name = os.environ.get(ENV_LOG_LEVEL, DEFAULT_LOG_LEVEL) # Change log level from str to int (note that log_level in function parameter # int already, coming from CLI argparse parameter). log_level = logging.getLevelName(log_level_name) - logging.basicConfig( - format="%(message)s", - stream=sys.stdout, - level=log_level, - ) + #logging.basicConfig( + # format="%(message)s", + # stream=sys.stdout, + # level=log_level, + #) shared_processors = [ _anonymizer,