https://prefect.io logo
d

Dima Anoshin

07/06/2023, 2:22 PM
Copy code
def log_it():
    logger = get_run_logger()
    <http://logger.info|logger.info>("INFO level log message.")
    logger.debug("You only see this message if the logging level is set to DEBUG. 🙂")
when we have a flow and we want to add logs, should logs be another flow or task?
👀 1
e

Emil Christensen

07/06/2023, 2:24 PM
You can use logs anywhere inside flows and tasks (and other python functions) as long as you get the
logger
. They do not have to be separated out.
The most important rule is that you’re in the scope of at least one flow. In other words, once you’re in a function decorated with
@flow
or inside a function it calls, you can log from there.
d

Dima Anoshin

07/06/2023, 2:30 PM
I see:
Copy code
@task(retries=4, retry_delay_seconds=0.1)
def save_weather(temp, windspeed, rain):
    logger = get_run_logger()
    <http://logger.info|logger.info>("Saving weather data...")
    with open("weather.csv", "w+") as w:
        w.write(str(temp) + ", " + str(windspeed) + ", " + str(rain) + "\n")
    <http://logger.info|logger.info>("Weather data saved successfully.")
    return "Successfully wrote temp, windspeed, and rain"
another question I have, for our past lab with weather, how cache or persist result can be helpful? and what is the difference between cache and persist result?
👀 1
e

Emil Christensen

07/06/2023, 2:35 PM
Let’s review results and caching when we regroup.