Cesar Hernandez
08/14/2024, 3:29 PMimport httpx
from prefect import flow
@flow()
def fetch_weather(lat: float = 38.9, lon: float = -77.0):
base_url = "<https://api.open-meteo.com/v1/forecast/>"
temps = httpx.get(
base_url,
params=dict(latitude=lat, longitude=lon, hourly="temperature_2m"),
)
forecasted_temp = float(temps.json()["hourly"]["temperature_2m"][0])
print(f"Forecasted temp C: {forecasted_temp} degrees")
return forecasted_temp
if __name__ == "__main__":
fetch_weather.serve(name="deploy-1")
But on the UI Logs I dont see any printing of the forecastedMarvin
08/14/2024, 3:30 PMprint
statements, but Prefect utilizes its own logging system. Here's how you can adjust your code:
1. Use Prefect's get_run_logger
for logging within your flow.
2. Ensure that logging is configured correctly.
Here is an example adjustment to your code:
python
import httpx
from prefect import flow, get_run_logger
@flow()
def fetch_weather(lat: float = 38.9, lon: float = -77.0):
logger = get_run_logger()
base_url = "<https://api.open-meteo.com/v1/forecast/>"
temps = httpx.get(
base_url,
params=dict(latitude=lat, longitude=lon, hourly="temperature_2m"),
)
forecasted_temp = float(temps.json()["hourly"]["temperature_2m"][0])
<http://logger.info|logger.info>(f"Forecasted temp C: {forecasted_temp} degrees")
return forecasted_temp
if __name__ == "__main__":
fetch_weather.serve(name="deploy-1")
This will use Prefect's logging system and should ensure that logs appear in the UI. If you're still facing issues, you might need to check your logging configurations or consult these references:
- Connecting & Troubleshooting Prefect Cloud
- Creating Interactive Workflows with Prefect
- Logging in Prefect
For specific issues, you might also find useful insights in related GitHub issues like:
- No logs shown after upgrading
- Prefect Cloud not receiving logs
If the problem persists, consider checking your Prefect server and client versions as compatibility issues might cause logging problems.