Fredrik
07/10/2025, 10:52 AMMarvin
07/10/2025, 10:52 AMMarvin
07/10/2025, 10:52 AMbash
export PREFECT_LOGGING_LEVEL=DEBUG
You can set this in your deployment environment or include it in your deployment configuration.
2. Using Python Code:
python
from prefect import flow
from prefect.logging import get_run_logger
@flow
def my_flow():
logger = get_run_logger()
logger.setLevel("DEBUG")
logger.debug("This is a debug message")
If you're using a deployment configuration file (yaml), you can include the environment variable:
yaml
deployments:
- name: my-deployment
flow_name: my-flow
env:
PREFECT_LOGGING_LEVEL: DEBUG
The environment variable approach is generally preferred as it allows you to modify logging behavior without changing your code. You can find more detailed information about logging customization in the documentation.
Remember that DEBUG level logging will produce significantly more output than the default INFO level, so use it judiciously, typically for development or troubleshooting purposes.Fredrik
07/10/2025, 11:31 AMMarvin
07/10/2025, 11:31 AMMarvin
07/10/2025, 11:32 AMlogging.yml
file isn't automatically transferred to the cloud execution environment.
2. Solutions:
A. Use Environment Variables (Recommended Approach):
Instead of using a logging.yml file, set the log levels using environment variables in your deployment configuration:
yaml
deployments:
- name: your-deployment
flow_name: your-flow
env:
PREFECT_LOGGING_LEVEL_PREFECT_FLOW_RUNS: DEBUG
PREFECT_LOGGING_LEVEL_PREFECT_TASK_RUNS: DEBUG
B. Package the Logging Configuration:
If you really need to use the YAML file, you'll need to:
1. Include the logging.yml file in your project
2. Set the PREFECT_LOGGING_CONFIG_PATH
to point to its location relative to your flow code
3. Ensure the file is deployed along with your flow code
3. Best Practices:
- Use environment variables for cloud deployments as they're more reliable and easier to manage
- Keep in mind that excessive DEBUG logging in cloud environments can impact performance
- You can verify the logging configuration is applied by checking the first few flow runs and confirming the debug messages appear
4. Verification:
To verify your logging configuration is working, you can add a simple debug message at the start of your flow:
python
from prefect import flow
from prefect.logging import get_run_logger
@flow
def my_flow():
logger = get_run_logger()
logger.debug("Debug logging test") # This should appear if configured correctly
Remember that while debug logging can be valuable for troubleshooting, it generates significantly more log data, which could impact performance and storage in a cloud environment. Use it judiciously and consider turning it off once you've resolved any issues you're investigating.Fredrik
07/10/2025, 11:36 AMMarvin
07/10/2025, 11:36 AMMarvin
07/10/2025, 11:37 AMyaml
deployments:
- name: your-deployment
flow_name: your-flow
env:
PREFECT_LOGGING_LEVEL: DEBUG
2. Enable Log Prints in Your Flow:
Make sure your flow and tasks are configured to capture prints:
python
from prefect import flow, task, get_run_logger
@task(log_prints=True)
def my_task():
logger = get_run_logger()
logger.debug("Debug message from task")
print("This will also be captured")
@flow(log_prints=True)
def my_flow():
logger = get_run_logger()
logger.debug("Debug message from flow")
my_task()
3. Verify Configuration:
You can verify the logging level is set correctly by adding a debug message at the start of your flow:
python
@flow(log_prints=True)
def my_flow():
logger = get_run_logger()
logger.debug("If you see this, DEBUG logging is enabled")
If you're still not seeing DEBUG logs in the UI after implementing these changes, you might need to:
1. Ensure the worker running your flow has the environment variable set
2. Check if there are any proxy or intermediary services that might be filtering logs
3. Verify that the flow is actually generating debug logs by checking the worker's local logs
Remember that excessive DEBUG logging can impact performance and generate large amounts of log data, so use it judiciously in production environments.