Gregory Hunt
08/14/2023, 2:27 PMNate
08/14/2023, 8:55 PMGregory Hunt
08/14/2023, 8:56 PMNate
08/14/2023, 9:49 PMhandlers:
# The handlers we define here will output all logs they receieve by default
# but we include the `level` so it can be overridden by environment
console:
level: 0
class: prefect.logging.handlers.PrefectConsoleHandler
formatter: json # <------ I made this change HERE
styles:
log.web_url: bright_blue
log.local_url: bright_blue
log.info_level: cyan
log.warning_level: yellow3
log.error_level: red3
log.critical_level: bright_red
log.completed_state: green
log.cancelled_state: yellow3
log.failed_state: red3
log.crashed_state: bright_red
log.flow_run_name: magenta
log.flow_name: bold magenta
and then set the logging settings path like
prefect config set PREFECT_LOGGING_SETTINGS_PATH=logging.yml
and so the consoles output becomes JSON formatted like
In [5]: @flow(log_prints=True)
...: def foo():
...: print("Hello!")
...:
In [6]: foo()
{"name":"prefect.engine","msg":"Created flow run 'careful-seagull' for flow 'foo'","args":[],"levelname":"INFO","levelno":20,"pathname":"/Users/nate/src/open-source/prefect-stuff/prefect/src/prefect/engine.py","filename":"engine.py","module":"engine","exc_info":null,"exc_text":null,"stack_info":null,"lineno":346,"funcName":"create_then_begin_flow_run","created":1692049727.434399,"msecs":434.0,"relativeCreated":116433.02083015442,"thread":6121811968,"threadName":"GlobalEventLoopThread","processName":"MainProcess","process":28969,"severity":"INFO"}
...
Gregory Hunt
08/15/2023, 12:51 PM