prefect.logging.handlers

Classes

APILogWorker

Methods:

max_batch_size

max_batch_size(self) -> int

min_interval

min_interval(self) -> float | None

instance

instance(cls: Type[Self], *args: Any) -> Self

APILogHandler

A logging handler that sends logs to the Prefect API.

Sends log records to the APILogWorker which manages sending batches of logs in the background.

Methods:

flush

flush(self) -> None

Tell the APILogWorker to send any currently enqueued logs and block until completion.

Use aflush from async contexts instead.

emit

emit(self, record: logging.LogRecord) -> None

Send a log to the APILogWorker

handleError

handleError(self, record: logging.LogRecord) -> None

prepare

prepare(self, record: logging.LogRecord) -> Dict[str, Any]

Convert a logging.LogRecord to the API LogCreate schema and serialize.

This infers the linked flow or task run from the log record or the current run context.

If a flow run id cannot be found, the log will be dropped.

Logs exceeding the maximum size will be dropped.

WorkerAPILogHandler

Methods:

emit

emit(self, record: logging.LogRecord) -> None

prepare

prepare(self, record: logging.LogRecord) -> Dict[str, Any]

Convert a logging.LogRecord to the API LogCreate schema and serialize.

This will add in the worker id to the log.

Logs exceeding the maximum size will be dropped.

PrefectConsoleHandler

Methods:

emit

emit(self, record: logging.LogRecord) -> None