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

Hannah Amundson

08/11/2020, 4:54 PM
i have a question about logging best practices. so i understand that to get the prefect logger we need to do
Copy code
prefect.context.get("logger")
How do we get that logger inside of each of our classes/functions that are being called within tasks? Is the best practice to just pass it in as a parameter?
j

Jim Crist-Harif

08/11/2020, 5:20 PM
If you're calling from inside a class based task (e.g. a subclass of
Task
) you can use the
logger
attribute directly. Otherwise either getting from
prefect.context
or calling
prefect.utilities.logging.get_logger
directly should work the same.
Whether you want to pass around the logger as an argument, or re-retrieve it inside helper functions using one of the above is up to you.
a

alex

08/11/2020, 5:56 PM
You could also use the python logger and log to stdout and enable
log_stdout
for your tasks
h

Hannah Amundson

08/12/2020, 4:11 PM
thank you
to both @Jim Crist-Harif and @alex