Unable to add my logging Handler to the default Task's logger #3252
Answered
by
cicdw
sierrezinal
asked this question in
Q&A
-
from prefect.utilities.logging import get_logger
rotater = RotatingFileHandler(str(root / 'output.log'), mode='a',
maxBytes=5 * 1024 * 1024, backupCount=2,
encoding='utf-8', delay=1)
rotater.setLevel(logging.INFO)
rotater.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
task_logger = get_logger("Task")
task_logger.addHandler(rotater)
flow.run() In my task @task
def transform(df: pd.DataFrame) -> pd.DataFrame:
logger = prefect.context.get("logger")
logger.info('blah blah') I do see the output in stdout but no log file is created. |
Beta Was this translation helpful? Give feedback.
Answered by
cicdw
Sep 3, 2020
Replies: 1 comment 3 replies
-
Hi @sierrezinal - the task logger uses the name of your task as the logger name, so if you use task_logger = get_logger("transform") I think it should work as you expect |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
sierrezinal
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @sierrezinal - the task logger uses the name of your task as the logger name, so if you use
I think it should work as you expect