prefect.logging.loggers
¶
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 prefect/logging/loggers.py
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 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
|
emit
¶
The logging.Handler implementation, not intended to be called directly.
Source code in prefect/logging/loggers.py
354 355 356 |
|
text
¶
Return the collected logs as a single newline-delimited string
Source code in prefect/logging/loggers.py
358 359 360 |
|
PrefectLogAdapter
¶
Bases: LoggerAdapter
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.
Source code in prefect/logging/loggers.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
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.
Source code in prefect/logging/loggers.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
|
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 its original state.
Source code in prefect/logging/loggers.py
246 247 248 249 250 251 252 253 254 |
|
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.
Source code in prefect/logging/loggers.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
get_logger
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 prefect/logging/loggers.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
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 |
---|---|
RuntimeError
|
If no context can be found |
Source code in prefect/logging/loggers.py
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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
patch_print
¶
Patches the Python builtin print
method to use print_as_log
Source code in prefect/logging/loggers.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
|
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.
Source code in prefect/logging/loggers.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
|
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
.
Source code in prefect/logging/loggers.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|
"""