Skip to content

Commit

Permalink
feat: make structlog configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
souvikg10 committed Oct 24, 2023
1 parent 936a8ed commit 1be1c7d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion rasa/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
16 changes: 10 additions & 6 deletions rasa/utils/log_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1be1c7d

Please sign in to comment.