Logging
zenml.logging
Modules
step_logging
ZenML logging handler.
Classes
PipelineLogsStorage(logs_uri: str, artifact_store: BaseArtifactStore, max_queue_size: int = LOGS_STORAGE_MAX_QUEUE_SIZE, queue_timeout: int = LOGS_STORAGE_QUEUE_TIMEOUT, write_interval: int = LOGS_WRITE_INTERVAL_SECONDS, merge_files_interval: int = LOGS_MERGE_INTERVAL_SECONDS)
Helper class which buffers and stores logs to a given URI using a background thread.
Initialization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logs_uri
|
str
|
the URI of the log file or folder. |
required |
artifact_store
|
BaseArtifactStore
|
Artifact Store from the current step context |
required |
max_queue_size
|
int
|
maximum number of individual messages to queue. |
LOGS_STORAGE_MAX_QUEUE_SIZE
|
queue_timeout
|
int
|
timeout in seconds for putting items in queue when full. - Positive value: Wait N seconds, then drop logs if queue still full - Negative value: Block indefinitely until queue has space (never drop logs) |
LOGS_STORAGE_QUEUE_TIMEOUT
|
write_interval
|
int
|
the amount of seconds before the created files get written to the artifact store. |
LOGS_WRITE_INTERVAL_SECONDS
|
merge_files_interval
|
int
|
the amount of seconds before the created files get merged into a single file. |
LOGS_MERGE_INTERVAL_SECONDS
|
Source code in src/zenml/logging/step_logging.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 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 |
|
merge_log_files(merge_all_files: bool = False) -> None
Merges all log files into one in the given URI.
Called on the logging context exit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
merge_all_files
|
bool
|
whether to merge all files or only raw files |
False
|
Source code in src/zenml/logging/step_logging.py
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 |
|
send_merge_event() -> None
Send a merge event to the log storage thread.
Source code in src/zenml/logging/step_logging.py
576 577 578 |
|
write(text: str) -> None
Main write method that sends individual messages directly to queue.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
the incoming string. |
required |
Source code in src/zenml/logging/step_logging.py
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
|
write_buffer(buffer_to_write: List[str]) -> None
Write the given buffer to file. This runs in the log storage thread.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
buffer_to_write
|
List[str]
|
The buffer contents to write to file. |
required |
Source code in src/zenml/logging/step_logging.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
|
PipelineLogsStorageContext(logs_uri: str, artifact_store: BaseArtifactStore, prepend_step_name: bool = True)
Context manager which patches stdout and stderr during pipeline run execution.
Initializes and prepares a storage object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logs_uri
|
str
|
the URI of the logs file. |
required |
artifact_store
|
BaseArtifactStore
|
Artifact Store from the current pipeline run context. |
required |
prepend_step_name
|
bool
|
Whether to prepend the step name to the logs. |
True
|
Source code in src/zenml/logging/step_logging.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 |
|
Functions
fetch_logs(zen_store: BaseZenStore, artifact_store_id: Union[str, UUID], logs_uri: str, offset: int = 0, length: int = 1024 * 1024 * 16, strip_timestamp: bool = False) -> str
Fetches the logs from the artifact store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
zen_store
|
BaseZenStore
|
The store in which the artifact is stored. |
required |
artifact_store_id
|
Union[str, UUID]
|
The ID of the artifact store. |
required |
logs_uri
|
str
|
The URI of the artifact. |
required |
offset
|
int
|
The offset from which to start reading. |
0
|
length
|
int
|
The amount of bytes that should be read. |
1024 * 1024 * 16
|
strip_timestamp
|
bool
|
Whether to strip timestamps in logs or not |
False
|
Returns:
Type | Description |
---|---|
str
|
The logs as a string. |
Raises:
Type | Description |
---|---|
DoesNotExistException
|
If the artifact does not exist in the artifact store. |
Source code in src/zenml/logging/step_logging.py
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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 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 224 225 226 227 228 229 230 231 232 233 234 235 |
|
prepare_logs_uri(artifact_store: BaseArtifactStore, step_name: Optional[str] = None, log_key: Optional[str] = None) -> str
Generates and prepares a URI for the log file or folder for a step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
artifact_store
|
BaseArtifactStore
|
The artifact store on which the artifact will be stored. |
required |
step_name
|
Optional[str]
|
Name of the step. Skipped for global pipeline run logs. |
None
|
log_key
|
Optional[str]
|
The unique identification key of the log file. |
None
|
Returns:
Type | Description |
---|---|
str
|
The URI of the log storage (file or folder). |
Source code in src/zenml/logging/step_logging.py
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 |
|
remove_ansi_escape_codes(text: str) -> str
Auxiliary function to remove ANSI escape codes from a given string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
the input string |
required |
Returns:
Type | Description |
---|---|
str
|
the version of the input string where the escape codes are removed. |
Source code in src/zenml/logging/step_logging.py
70 71 72 73 74 75 76 77 78 79 |
|
setup_orchestrator_logging(run_id: UUID, deployment: PipelineDeploymentResponse, logs_response: Optional[LogsResponse] = None) -> Any
Set up logging for an orchestrator environment.
This function can be reused by different orchestrators to set up consistent logging behavior.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
run_id
|
UUID
|
The pipeline run ID. |
required |
deployment
|
PipelineDeploymentResponse
|
The deployment of the pipeline run. |
required |
logs_response
|
Optional[LogsResponse]
|
The logs response to continue from. |
None
|
Returns:
Type | Description |
---|---|
Any
|
The logs context (PipelineLogsStorageContext) |
Source code in src/zenml/logging/step_logging.py
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 |
|