How to override default logging.yml file with custom logging.yml file

We are using prefect for some of our integrations for the first time. We are curious if we can use our own custom logging.yml file so we can set things globally. Is this possible?

2 Likes

Yes you can use your own custom logging.yml

From Logging - Prefect 2

There is a logging.yml file packaged with Prefect that defines the default logging configuration.

You can customize logging configuration by creating your own version of logging.yml with custom settings, by either creating the file at the default location (/.prefect/logging.yml) or by specifying the path to the file with PREFECT_LOGGING_SETTINGS_PATH. (If the file does not exist at the specified location, Prefect ignores the setting and uses the default configuration.)

1 Like

i am trying to set PREFECT_LOGGING_SETTINGS_PATH to the path i want but not having much luck. This is what i have tried.

Try setting it in the CLI:

1 Like

Given that you already asked the same, I’m moving your question from another thread here:

Question

“How can i set the value of a setting. Specifically i would like to give the PREFECT_LOGGING_SETTINGS_PATH setting a different path to use. Is there any way someone can post an example of this being done?”

Answer

As Andrew described, you would generally do it using

prefect config set PREFECT_LOGGING_SETTINGS_PATH="/Users/you/logging.yaml"

But this must be done from the CLI and set to an explicit path.

Does it answer your question?

For the most part. Can i call the cli from my python scripts and set this before i start using my flows and tasks? If so is there an example of where this is done?

1 Like

You could add this in the beginning of your flow:

import subprocess

subprocess.run('prefect config set PREFECT_LOGGING_SETTINGS_PATH="/Users/you/logging.yaml"', shell=True)

But you should be able to set it via CLI only once rather than via every flow. The flow should be business logic (without hardcoding environment information) and infra/deployments/configuration can be done from CLI.