Logging
zenml.logging
Modules
step_logging
ZenML logging handler.
Classes
ArtifactStoreHandler(storage: PipelineLogsStorage)
Bases: Handler
Handler that writes log messages to artifact store storage.
Initialize the handler with a storage instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
storage
|
PipelineLogsStorage
|
The PipelineLogsStorage instance to write to. |
required |
Source code in src/zenml/logging/step_logging.py
128 129 130 131 132 133 134 135 136 137 138 |
|
emit(record: logging.LogRecord) -> None
Emit a log record to the storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record
|
LogRecord
|
The log record to emit. |
required |
Source code in src/zenml/logging/step_logging.py
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 |
|
LogEntry
Bases: BaseModel
A structured log entry with parsed information.
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
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
|
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
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 |
|
send_merge_event() -> None
Send a merge event to the log storage thread.
Source code in src/zenml/logging/step_logging.py
721 722 723 |
|
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
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 575 576 577 578 579 |
|
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
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 |
|
PipelineLogsStorageContext(logs_uri: str, artifact_store: BaseArtifactStore, prepend_step_name: bool = True)
Context manager which collects logs 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
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 |
|
Functions
fetch_log_records(zen_store: BaseZenStore, artifact_store_id: Union[str, UUID], logs_uri: str) -> List[LogEntry]
Fetches log entries.
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 (file or directory). |
required |
Returns:
Type | Description |
---|---|
List[LogEntry]
|
List of log entries. |
Source code in src/zenml/logging/step_logging.py
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 |
|
parse_log_entry(log_line: str) -> Optional[LogEntry]
Parse a single log entry into a LogEntry object.
Handles two formats: 1. JSON format: {"timestamp": "...", "level": "...", "message": "...", "location": "..."} Uses Pydantic's model_validate_json for automatic parsing and validation. 2. Plain text: Any other text (defaults to INFO level)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
log_line
|
str
|
A single log line to parse |
required |
Returns:
Type | Description |
---|---|
Optional[LogEntry]
|
LogEntry object. For JSON logs, all fields are validated and parsed automatically. |
Optional[LogEntry]
|
For plain text logs, only message is populated with INFO level default. |
Optional[LogEntry]
|
Returns None only for empty lines. |
Source code in src/zenml/logging/step_logging.py
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 |
|
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
283 284 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 |
|
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
234 235 236 237 238 239 240 241 242 243 |
|
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
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 |
|