Skip to content

Commit 655f843

Browse files
committed
chore(oso_core): allow logging to be configured via env var
1 parent 8fd1468 commit 655f843

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/oso-core/oso_core/logging/defaults.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import os
23

34
import structlog
45

@@ -29,7 +30,11 @@ def ensure_event_type(
2930
return event_dict
3031

3132

32-
def configure_structured_logging() -> None:
33+
def configure_structured_logging(
34+
*,
35+
enable_json_logs: bool = os.environ.get("OSO_ENABLE_JSON_LOGS", "0")
36+
in ["true", "1"],
37+
) -> None:
3338
"""Configure structured logging for the application. This was taken almost
3439
directly from the structlog docs. See:
3540
@@ -53,6 +58,7 @@ def configure_structured_logging() -> None:
5358
structlog.stdlib.add_log_level,
5459
timestamper,
5560
structlog.processors.StackInfoRenderer(),
61+
structlog.processors.ExceptionRenderer(),
5662
ensure_event_type,
5763
]
5864

@@ -73,7 +79,9 @@ def configure_structured_logging() -> None:
7379
processors=[
7480
# Remove _record & _from_structlog.
7581
structlog.stdlib.ProcessorFormatter.remove_processors_meta,
76-
structlog.processors.JSONRenderer(),
82+
structlog.processors.JSONRenderer()
83+
if enable_json_logs
84+
else structlog.dev.ConsoleRenderer(),
7785
],
7886
)
7987

0 commit comments

Comments
 (0)