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

Class LoggingHandler

plain2code_logger.py:57–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55
56
57class LoggingHandler(logging.Handler):
58 def __init__(self, event_bus: EventBus, run_state: RunState):
59 super().__init__()
60 self.event_bus = event_bus
61 self.run_state = run_state
62
63 def emit(self, record):
64 try:
65 offset_seconds = self.run_state.render_time_accumulated + int(
66 time.monotonic() - self.run_state.last_render_start_timestamp
67 )
68
69 hours = offset_seconds // 3600
70 minutes = (offset_seconds % 3600) // 60
71 seconds = offset_seconds % 60
72 timestamp = f"{hours:02d}:{minutes:02d}:{seconds:02d}"
73
74 event = LogMessageEmitted(
75 logger_name=record.name,
76 level=record.levelname,
77 message=record.getMessage(),
78 timestamp=timestamp,
79 )
80 self.event_bus.publish(event)
81 except RuntimeError:
82 # We're going to get this crash after the TUI app is closed (forcefully).
83 # NOTE: This should be more thought out.
84 pass
85 except Exception:
86 self.handleError(record)
87
88
89class CrashLogHandler(logging.Handler):

Callers 1

setup_loggingFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected