File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
lib/oso-core/oso_core/logging Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change 11import logging
2+ import os
23
34import 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
You can’t perform that action at this time.
0 commit comments