Tim Galvin
04/27/2023, 6:33 AMon_completion
and on_failure
hooks made available for tasks and flows. In the past I would put cleanup / success logic as a distinct task
in my pipeline. These tasks have their own loggers that would report some items.
The following is with regards to callbacks supplied to the on_completion
and on_failure
hooks of a flow.
What is the correct way of using the logging
module and a logger
object to emit info/warn messages that are also recorded by the prefect server? A logger = get_run_logger()
call in one of my on_completion
callback functions raised a context error, and print
statements with log_print=True
don't seem to be captured either.
I guess ultimately I am curious about whether these call back functions are extecuted within or outside a flow context.Justin Trautmann
04/27/2023, 7:30 AMdef task_completion_hook(task, task_run, state):
from prefect.logging.loggers import task_run_logger
logger = task_run_logger(task_run, task)
logger.warn("TEST")
Tim Galvin
04/27/2023, 7:37 AMflow_run_logger
and passed through the flow_run
and flow
objects that are passed to the call back and worked like a charm.
I was not able to find them referenced in the docs. Would you happen to know where they are described? I am blind (in the literal sense) and may have overlooked themJustin Trautmann
04/27/2023, 8:38 AMget_run_logger
method.Tim Galvin
04/27/2023, 9:09 AMget_run_logger
method?Justin Trautmann
04/27/2023, 9:36 AM