Jacques
04/30/2020, 2:51 PMDylan
trace_id
, or all logs emitted by your task code with:
@task
def my_task():
logger = prefect.context.get("logger")
<http://logger.info|logger.info>("An info message.")
logger.warning("A warning message.")
Jacques
04/30/2020, 2:56 PMDylan
Jacques
04/30/2020, 2:59 PMDylan
trace_id
in dependencies and then write a small custom logger that accepted the trace_id
as a parameterJacques
04/30/2020, 3:01 PMDylan
Jacques
04/30/2020, 3:01 PMDylan
trace_id
to your flow context, it would be accessible in all of your tasks and you’d be able to add it to all of your logs.
Here’s some documentation that should be helpful:
https://docs.prefect.io/api/latest/utilities/context.html#context
https://docs.prefect.io/core/advanced_tutorials/custom-logs.html#an-example
Here’s where we make context available to loggers: https://github.com/PrefectHQ/prefect/blob/master/src/prefect/utilities/logging.py#L170
Let me know if this helps!Jacques
04/30/2020, 3:13 PMDylan
Jacques
04/30/2020, 3:57 PMtask_logger = get_logger("Task")
test_handler = logging.StreamHandler()
formatter = logging.Formatter("#############%(message)s")
test_handler.setFormatter(formatter)
task_logger.addHandler(test_handler)
This is just a test, but it seems to have no impactDylan
Jacques
04/30/2020, 4:03 PMprefect.utilities.prefect.utilities.logging.PREFECT_LOG_RECORD_ATTRIBUTES = (
PREFECT_LOG_RECORD_ATTRIBUTES + ("trace_id",)
)
Seems very hacky though 🙂Dylan
.prefect/config.toml
file or by environment variable with PREFECT__LOGGING__FORMAT="[%(asctime)s] %(levelname)s - %(name)s | %(message)s"
working for you?Jacques
04/30/2020, 4:21 PMDylan
Jacques
04/30/2020, 4:21 PMDylan
Jacques
04/30/2020, 4:23 PMDylan
Jacques
04/30/2020, 4:26 PMDylan
Jacques
04/30/2020, 4:30 PMDylan