<@ULVA73B9P> how do I update the formatter from st...
# ask-marvin
d
@Marvin how do I update the formatter from standard to json?
m
To update the log formatter in Prefect to JSON, you can modify the logging configuration. Prefect uses Python's logging module, and you can customize the format by setting the appropriate environment variables or by modifying the
logging.yml
file. Here's a concise approach to achieve this: 1. Modify `logging.yml`: Update the
formatter
section in your
logging.yml
file to use a JSON formatter. This typically involves specifying a JSON format string. 2. Environment Variables: If you prefer not to use a
logging.yml
file, you can set the format via environment variables that Prefect uses to configure logging. For more detailed guidance, you can refer to the Prefect Logging Documentation. If you need further assistance with the exact configuration or syntax, please let me know!
d
@Marvin how can I do it in Prefect Cloud?
m
In Prefect Cloud, updating the log formatter to JSON involves configuring your logging settings remotely. Unfortunately, the documentation does not provide explicit steps for modifying the log formatter directly within Prefect Cloud. However, you can typically achieve this by: 1. Environment Variables: Set the appropriate environment variables in your Prefect Cloud environment to specify JSON formatting. This might involve setting variables that Prefect uses to configure logging, similar to local settings. 2. Custom Configuration: If you have access to modify the configuration files or settings in your Prefect Cloud environment, you can define a custom
logging.yml
file with JSON formatting. For more specific instructions, you may need to consult Prefect's support or documentation related to Prefect Cloud configurations. You can start by exploring the Prefect Cloud Troubleshooting Guide for additional guidance. If you have more specific requirements or constraints, feel free to share them!
n
the logger config you do client side is the same regardless if you're connected to your own server or cloud
d
in my python code I'm calling
logger = get_run_logger()
and it is using the https://github.com/PrefectHQ/prefect/blob/main/src/prefect/logging/logging.yml#L11 "standard", I'd like it to use "json"
n
yep, marvin's first suggestion is probably what you want to do https://docs-3.prefect.io/v3/develop/logging#logging-configuration
d
hum... is that file read by the work pool worker?
n
if you want to configure the worker's logging, then you'd set the env var to use the custom logging yaml file for that process, yes but if you just care about the single change, you can take the docs suggestion and set the specific env var using
PREFECT_LOGGING_{PATH}_{TO}___{CONFIG}
Copy code
» PREFECT_LOGGING_HANDLERS_CONSOLE_FORMATTER=json uvx prefect worker start --pool local

Discovered type 'process' for work pool 'local'.
Worker 'ProcessWorker 81fb3946-021f-41b5-893d-670bbc02a665' started!
{"name":"prefect.flow_runs.worker","msg":"Worker 'ProcessWorker 81fb3946-021f-41b5-893d-670bbc02a665' submitting flow run '27dbc9b6-9666-40bb-b746-80b4e33e29fd'","args":[],"levelname":"INFO","levelno":20,"pathname":"/Users/nate/Library/Caches/uv/archive-v0/A278kD7gqcA3TRYQZ-5FO/lib/python3.12/site-packages/prefect/workers/base.py","filename":"base.py","module":"base","exc_info":null,"exc_text":null,"stack_info":null,"lineno":906,"funcName":"_submit_scheduled_flow_runs","created":1738348616.1268811,"msecs":126.0,"relativeCreated":27761.27529144287,"thread":8487322176,"threadName":"MainThread","processName":"MainProcess","process":99821,"taskName":"functools","flow_run_name":"shapeless-markhor","flow_run_id":"27dbc9b6-9666-40bb-b746-80b4e33e29fd","flow_name":"<unknown>","worker_name":"ProcessWorker 81fb3946-021f-41b5-893d-670bbc02a665","work_pool_name":"local","work_pool_id":"c0f5296e-8607-4e2d-9fee-36a5f10af95f","worker_id":"0d03f6ef-c95d-487f-acc4-270562d91ddb","message":"Worker 'ProcessWorker 81fb3
👀 1
d
Thanks @Nate