loggers
prefect.logging.loggers
Functions
get_logger
Get a prefect
logger. These loggers are intended for internal use within the
prefect
package.
See get_run_logger
for retrieving loggers for use within task or flow runs.
By default, only run-related loggers are connected to the APILogHandler
.
get_run_logger
Get a Prefect logger for the current task run or flow run.
The logger will be named either prefect.task_runs
or prefect.flow_runs
.
Contextual data about the run will be attached to the log records.
These loggers are connected to the APILogHandler
by default to send log records to
the API.
Args:
context
: A specific context may be provided as an override. By default, the context is inferred from global state and this should not be needed.**kwargs
: Additional keyword arguments will be attached to the log records in addition to the run metadata
Raises:
MissingContextError
: If no context can be found
flow_run_logger
Create a flow run logger with the run’s metadata attached.
Additional keyword arguments can be provided to attach custom data to the log records.
If the flow run context is available, see get_run_logger
instead.
task_run_logger
Create a task run logger with the run’s metadata attached.
Additional keyword arguments can be provided to attach custom data to the log records.
If the task run context is available, see get_run_logger
instead.
If only the flow run context is available, it will be used for default values
of flow_run
and flow
.
get_worker_logger
Create a worker logger with the worker’s metadata attached.
If the worker has a backend_id, it will be attached to the log records. If the worker does not have a backend_id a basic logger will be returned. If the worker does not have a backend_id attribute, a basic logger will be returned.
disable_logger
Get a logger by name and disables it within the context manager. Upon exiting the context manager, the logger is returned to its original state.
disable_run_logger
Gets both prefect.flow_run
and prefect.task_run
and disables them
within the context manager. Upon exiting the context manager, both loggers
are returned to their original state.
print_as_log
A patch for print
to send printed messages to the Prefect run logger.
If no run is active, print
will behave as if it were not patched.
If print
sends data to a file other than sys.stdout
or sys.stderr
, it will
not be forwarded to the Prefect logger either.
patch_print
Patches the Python builtin print
method to use print_as_log
Classes
PrefectLogAdapter
Adapter that ensures extra kwargs are passed through correctly; without this
the extra
fields set on the adapter would overshadow any provided on a
log-by-log basis.
See https://bugs.python.org/issue32732 — the Python team has declared that this is not a bug in the LoggingAdapter and subclassing is the intended workaround.
Methods:
process
getChild
LogEavesdropper
A context manager that collects logs for the duration of the context
Example:
The logging.Handler implementation, not intended to be called directly.
text
Return the collected logs as a single newline-delimited string