Skip to content

Commit 2895e1f

Browse files
authored
Logging fixes (#273)
* Allow passing dictionaries to logging statement extras * Fix configure_logging to enable INFO level with no arguments
1 parent 5045dcd commit 2895e1f

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/fastcs/launch.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,7 @@ def run(
105105
help=f"A yaml file matching the {controller_class.__name__} schema"
106106
),
107107
],
108-
log_level: Annotated[
109-
Optional[LogLevel], # noqa: UP045
110-
typer.Option(),
111-
] = None,
108+
log_level: Annotated[LogLevel, typer.Option()] = LogLevel.INFO,
112109
graylog_endpoint: Annotated[
113110
Optional[GraylogEndpoint], # noqa: UP045
114111
typer.Option(

src/fastcs/logging/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
drivers. This logger uses ``loguru`` as underlying logging library, which enables much
1717
simpler configuration as well as structured logging.
1818
19-
Keyword arguments to log statments will be attached as extra fields on the log record.
19+
Keyword arguments to log statements will be attached as extra fields on the log record.
2020
These fields are displayed separately in the console output and can used for filtering
2121
and metrics in graylog.
2222
@@ -70,7 +70,7 @@ def bind_logger(logger_name: str) -> Logger:
7070

7171

7272
def configure_logging(
73-
level: LogLevel | None = None,
73+
level: LogLevel = LogLevel.INFO,
7474
graylog_endpoint: GraylogEndpoint | None = None,
7575
graylog_static_fields: GraylogStaticFields | None = None,
7676
graylog_env_fields: GraylogEnvFields | None = None,
@@ -95,7 +95,7 @@ def configure_logging(
9595

9696

9797
# Configure logger with defaults - INFO level and disabled
98-
configure_logging()
98+
_configure_logger(logger)
9999

100100

101101
class _StdLoggingInterceptHandler(logging.Handler):

src/fastcs/logging/_logging.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ def format_record(record) -> str:
8787
else:
8888
extras = ""
8989

90+
# Escape braces so Loguru doesn't parse them as format placeholders
91+
extras = extras.replace("{", "{{").replace("}", "}}")
92+
9093
return f"""\
9194
<level>[{time} {record["level"].name[0]}]</level> \
9295
{record["message"]:<80} \

0 commit comments

Comments
 (0)