-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush_log.py
More file actions
47 lines (38 loc) · 1.27 KB
/
push_log.py
File metadata and controls
47 lines (38 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""Push log: record what was pushed, deduped, and filtered for analytics."""
from __future__ import annotations
import json
import logging
from datetime import UTC, datetime
from pathlib import Path
log = logging.getLogger(__name__)
def write_push_log(
log_dir: str | Path,
flow: str,
items_pushed: list[dict],
items_deduped: int,
items_filtered: int,
items_raw: int,
alerts: list[dict],
) -> Path:
"""Append a push log entry as JSONL (one line per push cycle).
Returns the log file path.
"""
log_path = Path(log_dir) / "push_log.jsonl"
log_path.parent.mkdir(parents=True, exist_ok=True)
entry = {
"ts": datetime.now(UTC).isoformat(),
"flow": flow,
"raw": items_raw,
"after_dedup": items_raw - items_deduped,
"deduped": items_deduped,
"filtered_seen": items_filtered,
"pushed": len(items_pushed),
"items": items_pushed,
"alerts": [a.get("msg", "") for a in alerts] if alerts else [],
}
with open(log_path, "a", encoding="utf-8") as f:
f.write(json.dumps(entry, ensure_ascii=False) + "\n")
log.info(
f"push log: {log_path} (raw={items_raw} dedup=-{items_deduped} seen=-{items_filtered} pushed={len(items_pushed)})"
)
return log_path