(self, event_type, request_id=None, **fields)
| 25 | self._buffer = [] # 内存镜像(便于查询/测试) |
| 26 | |
| 27 | def append(self, event_type, request_id=None, **fields): |
| 28 | record = {"ts": time.time(), "type": event_type, "request_id": request_id} |
| 29 | record.update(fields) |
| 30 | line = json.dumps(record, ensure_ascii=False) |
| 31 | with self._lock: |
| 32 | self._buffer.append(record) |
| 33 | if self.path: |
| 34 | with open(self.path, "a", encoding="utf-8") as f: |
| 35 | f.write(line + "\n") |
| 36 | return record |
| 37 | |
| 38 | def events(self, request_id=None, event_type=None): |
| 39 | with self._lock: |
no outgoing calls