From 565d4cab310c73935ba24eca95f155c8a8fdebe8 Mon Sep 17 00:00:00 2001 From: Gary Yendell Date: Thu, 13 Nov 2025 13:00:05 +0000 Subject: [PATCH 1/2] Allow passing dictionaries to logging statement extras --- src/fastcs/logging/_logging.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fastcs/logging/_logging.py b/src/fastcs/logging/_logging.py index 1114a6db..3dc2ba2f 100644 --- a/src/fastcs/logging/_logging.py +++ b/src/fastcs/logging/_logging.py @@ -87,6 +87,9 @@ def format_record(record) -> str: else: extras = "" + # Escape braces so Loguru doesn't parse them as format placeholders + extras = extras.replace("{", "{{").replace("}", "}}") + return f"""\ [{time} {record["level"].name[0]}] \ {record["message"]:<80} \ From aaa89d321ef604bbae3173f38a397ec1d1895204 Mon Sep 17 00:00:00 2001 From: Gary Yendell Date: Thu, 20 Nov 2025 16:09:40 +0000 Subject: [PATCH 2/2] Fix configure_logging to enable INFO level with no arguments --- src/fastcs/launch.py | 5 +---- src/fastcs/logging/__init__.py | 6 +++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/fastcs/launch.py b/src/fastcs/launch.py index eec14114..7165fbf8 100644 --- a/src/fastcs/launch.py +++ b/src/fastcs/launch.py @@ -105,10 +105,7 @@ def run( help=f"A yaml file matching the {controller_class.__name__} schema" ), ], - log_level: Annotated[ - Optional[LogLevel], # noqa: UP045 - typer.Option(), - ] = None, + log_level: Annotated[LogLevel, typer.Option()] = LogLevel.INFO, graylog_endpoint: Annotated[ Optional[GraylogEndpoint], # noqa: UP045 typer.Option( diff --git a/src/fastcs/logging/__init__.py b/src/fastcs/logging/__init__.py index 9c60ff3a..ba11b087 100644 --- a/src/fastcs/logging/__init__.py +++ b/src/fastcs/logging/__init__.py @@ -16,7 +16,7 @@ drivers. This logger uses ``loguru`` as underlying logging library, which enables much simpler configuration as well as structured logging. -Keyword arguments to log statments will be attached as extra fields on the log record. +Keyword arguments to log statements will be attached as extra fields on the log record. These fields are displayed separately in the console output and can used for filtering and metrics in graylog. @@ -70,7 +70,7 @@ def bind_logger(logger_name: str) -> Logger: def configure_logging( - level: LogLevel | None = None, + level: LogLevel = LogLevel.INFO, graylog_endpoint: GraylogEndpoint | None = None, graylog_static_fields: GraylogStaticFields | None = None, graylog_env_fields: GraylogEnvFields | None = None, @@ -95,7 +95,7 @@ def configure_logging( # Configure logger with defaults - INFO level and disabled -configure_logging() +_configure_logger(logger) class _StdLoggingInterceptHandler(logging.Handler):