prefect.logging
LogEavesdropper
Bases: Handler
A context manager that collects logs for the duration of the context
Example:
```python
import logging
from prefect.logging import LogEavesdropper
with LogEavesdropper("my_logger") as eavesdropper:
logging.getLogger("my_logger").info("Hello, world!")
logging.getLogger("my_logger.child_module").info("Another one!")
print(eavesdropper.text())
# Outputs: "Hello, world!
Another one!"
Source code in src/prefect/logging/loggers.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
|
__init__(eavesdrop_on, level=logging.NOTSET)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
eavesdrop_on
|
str
|
the name of the logger to eavesdrop on |
required |
level
|
int
|
the minimum log level to eavesdrop on; if omitted, all levels are captured |
NOTSET
|
Source code in src/prefect/logging/loggers.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
|
emit(record)
The logging.Handler implementation, not intended to be called directly.
Source code in src/prefect/logging/loggers.py
336 337 338 |
|
text()
Return the collected logs as a single newline-delimited string
Source code in src/prefect/logging/loggers.py
340 341 342 |
|
get_logger(name=None)
cached
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
.
Source code in src/prefect/logging/loggers.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
get_run_logger(context=None, **kwargs)
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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
Optional[RunContext]
|
A specific context may be provided as an override. By default, the context is inferred from global state and this should not be needed. |
None
|
**kwargs
|
str
|
Additional keyword arguments will be attached to the log records in addition to the run metadata |
{}
|
Raises:
Type | Description |
---|---|
MissingContextError
|
If no context can be found |
Source code in src/prefect/logging/loggers.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|