logger
This module defines RunLogger, the package's human-readable text log writer.
RunLogger
Constructor:
RunLogger(log_directory_path: str)
Behavior:
- stores the target directory path
- ensures the directory exists immediately
Main method:
write_log(run_context, result_bundle, run_config, note_message=None) -> str
Returns:
- the path to the written log file as a string
Side effects:
- creates the log directory if needed
- writes a text file to disk
Error conditions:
- the module does not perform much explicit validation; file-system errors would surface from the underlying write path
Generated API details
Responsible for writing a human-readable run log.
Source code in src/extraction_testing/logger.py
24
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 | class RunLogger:
"""Responsible for writing a human-readable run log."""
def __init__(self, log_directory_path: str):
"""Initialize with a log directory path."""
self.log_directory_path = log_directory_path
ensure_directory(self.log_directory_path)
def write_log(self, run_context: RunContext, result_bundle: ResultBundle, run_config: RunConfig, note_message: Optional[str] = None) -> str:
"""Write a timestamped log file and return its path."""
filename = f"test_run_{run_context.run_identifier}.txt"
full_file_path_string = str(Path(self.log_directory_path) / filename)
with open(full_file_path_string, "w", encoding="utf-8") as file_handle:
file_handle.write(f"Run Identifier: {run_context.run_identifier}\n")
file_handle.write(f"Started At: {run_context.started_at_timestamp}\n")
file_handle.write(f"Configuration Hash: {run_context.configuration_hash}\n")
file_handle.write(f"Task Type: {run_config.task_type}\n")
file_handle.write("\n=== Total Metrics (averaged over features) ===\n")
file_handle.write(result_bundle.total_metrics_data_frame.to_string(index=False))
file_handle.write("\n\n=== Per-Feature Metrics (macro) ===\n")
file_handle.write(result_bundle.per_feature_metrics_data_frame.to_string(index=False))
file_handle.write(f"\n\nRow Accuracy: {result_bundle.row_accuracy_value:.4f}\n")
if result_bundle.entity_detection_summary:
file_handle.write("\n=== Entity Detection Summary ===\n")
for key, value in result_bundle.entity_detection_summary.items():
file_handle.write(f"{key}: {value}\n")
if note_message:
file_handle.write(f"\nNote: {note_message}\n")
return full_file_path_string
|
Initialize with a log directory path.
Source code in src/extraction_testing/logger.py
| def __init__(self, log_directory_path: str):
"""Initialize with a log directory path."""
self.log_directory_path = log_directory_path
ensure_directory(self.log_directory_path)
|
Write a timestamped log file and return its path.
Source code in src/extraction_testing/logger.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 | def write_log(self, run_context: RunContext, result_bundle: ResultBundle, run_config: RunConfig, note_message: Optional[str] = None) -> str:
"""Write a timestamped log file and return its path."""
filename = f"test_run_{run_context.run_identifier}.txt"
full_file_path_string = str(Path(self.log_directory_path) / filename)
with open(full_file_path_string, "w", encoding="utf-8") as file_handle:
file_handle.write(f"Run Identifier: {run_context.run_identifier}\n")
file_handle.write(f"Started At: {run_context.started_at_timestamp}\n")
file_handle.write(f"Configuration Hash: {run_context.configuration_hash}\n")
file_handle.write(f"Task Type: {run_config.task_type}\n")
file_handle.write("\n=== Total Metrics (averaged over features) ===\n")
file_handle.write(result_bundle.total_metrics_data_frame.to_string(index=False))
file_handle.write("\n\n=== Per-Feature Metrics (macro) ===\n")
file_handle.write(result_bundle.per_feature_metrics_data_frame.to_string(index=False))
file_handle.write(f"\n\nRow Accuracy: {result_bundle.row_accuracy_value:.4f}\n")
if result_bundle.entity_detection_summary:
file_handle.write("\n=== Entity Detection Summary ===\n")
for key, value in result_bundle.entity_detection_summary.items():
file_handle.write(f"{key}: {value}\n")
if note_message:
file_handle.write(f"\nNote: {note_message}\n")
return full_file_path_string
|