# spins up a local webserver running at http://0.0.0.0:8000/python3-mhttp.server
接下来,创建一个logger处理器,并将该处理器添加到task的日志对象中。
import loggingimport requestsimport prefectfrom prefect import task, Flowfrom prefect.utilities.logging import get_loggerclassMyHandler(logging.StreamHandler):defemit(self,record): requests.post("http://0.0.0.0:8000/", params=dict(msg=record.msg))@task(name="Task A")deftask_a():return3@task(name="Task B")deftask_b(x): logger = prefect.context.get("logger") logger.debug("Beginning to run Task B with input {}".format(x)) y =3* x +1 logger.debug("Returning the value {}".format(y))return ywithFlow("logging-example")as flow: result =task_b(task_a)# now attach our custom handler to Task B's loggertask_logger =get_logger("Task")task_logger.addHandler(MyHandler())if__name__=="__main__": flow.run()