#!/usr/bin/env python3 """Read the server's access log and show it with usernames. Every request writes one JSON line on stderr (src/lib.rs, `request_log_line`): {"event":"request","method":"POST","path":"/compute/gemma","status":200, "took_ms":912,"request_id":"...","user":"zachs", "scheme":"opaque","token":"agent-ravanan-3"} `user` is already the gn-auth user id, so most lines need no translation. The `token` handle does: this script joins it against the token registry (`tokens.sqlite`, `GN4_API_TOKENS_DB`) and shows - the subject **as the registry has it now** -- a token's row is authoritative, so a handle whose target changed is visible; - the token's status *today* -- `active`, `expired` or `revoked` -- which is how you tell "an agent was working at 14:02" from "an agent was working at 14:02 with a credential that has since been revoked"; - the note on the row, e.g. what the token was minted for. Use it on a process log or a proxy log that carries `x-gn4-user`: journalctl -u genenetwork4 | scripts/gn4-log.py scripts/gn4-log.py -f /var/log/gn4.log --since 2026-11-14 --grep gemma scripts/gn4-log.py -f log.jsonl --json # enriched JSON, for jq scripts/gn4-log.py -f log.jsonl --summary # who ran what, counted Lines that are not JSON (a Ruby backtrace, a GEMMA progress bar) pass through unchanged unless --quiet; that is deliberate, because the process log interleaves them and dropping them would hide the interesting failures. """ from __future__ import annotations import argparse import json import os import re import sqlite3 import sys import time from collections import Counter from pathlib import Path DATE = re.compile(r"^(?P\d{4}-\d{2}-\d{2})") TIME = re.compile(r"(?P