https://prefect.io logo
#prefect-community
Title
# prefect-community
s

simone

07/15/2020, 3:02 PM
Hi, Is it possible to output the logs also to a file? thanks
j

josh

07/15/2020, 3:08 PM
Hi @simone do you mean all prefect logs or only logs from within your task? If doing the latter you could do something like this:
Copy code
import logging

import prefect
from prefect import task, Flow

@task
def log_to_file():
    logger = prefect.context.get("logger")
    file_handler = logging.FileHandler('my.log')
    file_handler.setLevel(logging.DEBUG)
    logger.addHandler(file_handler)

    <http://logger.info|logger.info>("I am log.")

f = Flow("log-file", tasks=[log_to_file])
f.run()
s

simone

07/15/2020, 6:30 PM
Hi Josh, thanks a lot! works great!