Log a structured event for machine parsing.
(
self,
event_type: str,
data: dict,
*,
timestamp: str | None = None,
to_stdout: bool = False,
)
| 903 | self._console.print(Rule(style=color or self._PAL_GREEN)) |
| 904 | |
| 905 | def event( |
| 906 | self, |
| 907 | event_type: str, |
| 908 | data: dict, |
| 909 | *, |
| 910 | timestamp: str | None = None, |
| 911 | to_stdout: bool = False, |
| 912 | ): |
| 913 | """ |
| 914 | Log a structured event for machine parsing. |
| 915 | """ |
| 916 | with self._lock: |
| 917 | payload = { |
| 918 | "type": event_type, |
| 919 | "timestamp": timestamp or datetime.now().isoformat(), |
| 920 | "data": data, |
| 921 | } |
| 922 | line = ( |
| 923 | f"{EVENT_START}{json.dumps(payload, ensure_ascii=False)}{EVENT_END}\n" |
| 924 | ) |
| 925 | self._append_line( |
| 926 | line, |
| 927 | log_path=self.event_log_path, |
| 928 | host_path=self.host_event_log_path, |
| 929 | to_stdout=to_stdout, |
| 930 | ) |
| 931 | self._render_event(event_type, data, timestamp=payload["timestamp"]) |
| 932 | |
| 933 | def log_event(self, logger, event_type: str, data: Dict[str, Any]): |
| 934 | event_fn = getattr(logger, "event", None) |
no test coverage detected