MCPcopy Index your code
hub / github.com/Codeplain-ai/codeplain / ElapsedTimeFormatter

Class ElapsedTimeFormatter

plain2code_logger.py:23–54  ·  view source on GitHub ↗

Formatter that adds elapsed time since render started, accounting for pauses.

Source from the content-addressed store, hash-verified

21
22
23class ElapsedTimeFormatter(logging.Formatter):
24 """Formatter that adds elapsed time since render started, accounting for pauses."""
25
26 def __init__(self, run_state: RunState, fmt: str = "%(elapsed_time)s %(levelname)s %(name)s: %(message)s"):
27 super().__init__(fmt=fmt)
28 self.run_state = run_state
29
30 def format(self, record):
31 # Calculate elapsed time the same way as LoggingHandler does for the TUI
32 try:
33 offset_seconds = self.run_state.render_time_accumulated + int(
34 time.monotonic() - self.run_state.last_render_start_timestamp
35 )
36 except Exception:
37 # If RunState is not available or there's any error, default to 00:00:00
38 offset_seconds = 0
39
40 hours = offset_seconds // 3600
41 minutes = (offset_seconds % 3600) // 60
42 seconds = offset_seconds % 60
43 elapsed_time = f"[{hours:02d}:{minutes:02d}:{seconds:02d}]"
44
45 # Add elapsed_time to the record so it can be used in the format string
46 record.elapsed_time = elapsed_time
47
48 # Handle multi-line messages with proper indentation
49 original_message = record.getMessage()
50 indent = " " * len(elapsed_time + " ")
51 modified_message = original_message.replace("\n", "\n" + indent)
52 record.msg = modified_message
53
54 return super().format(record)
55
56
57class LoggingHandler(logging.Handler):

Callers 2

setup_loggingFunction · 0.90
dump_crash_logsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected