Nimesh Kumar
07/01/2025, 3:41 PMMarvin
07/01/2025, 3:41 PMMarvin
07/01/2025, 3:42 PMbash
export PREFECT_LOGGING_LEVEL="DEBUG"
2. In-Code Configuration
You can also set the log level in your 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")
<http://logger.info|logger.info>("This is an info message")
3. Profile Configuration
You can set the logging level in your Prefect profile:
bash
prefect config set PREFECT_LOGGING_LEVEL="DEBUG"
4. Verify Log Handler Configuration
Make sure your logs are being properly captured by checking these settings:
bash
prefect config set PREFECT_LOGGING_SERVER_LEVEL="DEBUG"
prefect config set PREFECT_LOGGING_HANDLERS_DEFAULT_LEVEL="DEBUG"
If you're still not seeing logs after trying these steps, there are a few things to check:
1. Confirm you're actually generating logs at the DEBUG level in your code
2. Verify that your flow runs are completing successfully
3. Check that you're looking at the correct flow run in the UI
4. Make sure you're using the get_run_logger()
rather than Python's built-in logging
For more detailed information about logging configuration, you can check out the logging customization documentation.
Would you mind sharing:
1. How are you currently generating your logs?
2. Are you seeing any logs at all in the UI, or none?
This will help me provide more specific guidance for your situation.Nimesh Kumar
07/03/2025, 11:40 AMMarvin
07/03/2025, 11:40 AMMarvin
07/03/2025, 11:41 AMpython
from prefect import task, flow, get_run_logger
@task
async def my_task():
logger = get_run_logger()
<http://logger.info|logger.info>("This is an info message")
logger.warning("This is a warning")
logger.error("This is an error")
@flow
async def my_flow():
await my_task()
2. Capturing Print Statements
If you want print statements to show up in the logs, use the log_prints=True
parameter:
python
@task(log_prints=True)
async def my_task():
print("This will show up in the Prefect UI!")
3. Custom Log Levels
You can set custom log levels using environment variables:
bash
export PREFECT_LOGGING_LEVEL="DEBUG" # For more detailed logs
4. Viewing Logs in the UI
- Navigate to the Prefect UI
- Find your flow run
- Click on the specific task run
- View the logs in the "Logs" tab
5. Advanced Logging Configuration
For more control, you can create a custom logging configuration:
python
from prefect import task, flow
import logging
@task
async def my_task():
logger = get_run_logger()
logger.setLevel(logging.DEBUG)
logger.debug("Detailed debug information")
<http://logger.info|logger.info>("Processing step completed")
Important Notes:
- Logs are automatically captured and displayed in the Prefect UI
- The default log level is INFO
- You can use different log levels (DEBUG, INFO, WARNING, ERROR, CRITICAL) depending on your needs
- All logs are timestamped and include context about the flow and task run
To view the logs in the frontend:
1. Open the Prefect UI
2. Navigate to your flow run
3. Click on the specific task run
4. Look for the "Logs" tab, which will show all logged messages in chronological order
The logs will include:
- Timestamp
- Log level
- Message content
- Task/flow context
- Any additional metadata
For more detailed information about logging customization, you can refer to the Prefect logging documentation.