{"id":51039278,"url":"https://github.com/brandonkramer/jsonlreplay","last_synced_at":"2026-06-22T09:30:26.969Z","repository":{"id":361911526,"uuid":"1254988756","full_name":"brandonkramer/jsonlreplay","owner":"brandonkramer","description":"Append-only JSONL log with monotonic sequence numbers and incremental replay (sinceSeq, limit, Poll).","archived":false,"fork":false,"pushed_at":"2026-06-01T18:50:25.000Z","size":74,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-01T20:28:03.994Z","etag":null,"topics":["append-only","event-log","event-sourcing","go","golang","json-lines","jsonl","library","logging","replay"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brandonkramer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-31T08:56:13.000Z","updated_at":"2026-06-01T18:50:52.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/brandonkramer/jsonlreplay","commit_stats":null,"previous_names":["brandonkramer/jsonlreplay"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/brandonkramer/jsonlreplay","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonkramer%2Fjsonlreplay","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonkramer%2Fjsonlreplay/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonkramer%2Fjsonlreplay/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonkramer%2Fjsonlreplay/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brandonkramer","download_url":"https://codeload.github.com/brandonkramer/jsonlreplay/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonkramer%2Fjsonlreplay/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34643409,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-22T02:00:06.391Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["append-only","event-log","event-sourcing","go","golang","json-lines","jsonl","library","logging","replay"],"created_at":"2026-06-22T09:30:25.860Z","updated_at":"2026-06-22T09:30:26.964Z","avatar_url":"https://github.com/brandonkramer.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jsonlreplay\n\nAppend-only JSONL log with monotonic sequence numbers and incremental replay (`sinceSeq`, `limit`, `Poll`).\n\nEach line is one JSON object (`seq`, optional `time`, `kind`, `text`, `data`) so logs stay easy to inspect with `jq`, `rg`, or an editor.\n\n## Install\n\nFrom [pkg.go.dev](https://pkg.go.dev/github.com/brandonkramer/jsonlreplay):\n\n```bash\ngo get github.com/brandonkramer/jsonlreplay@v0.1.0\n```\n\n## Quick start\n\n```go\nw, err := jsonlreplay.Open(\"/var/log/myapp/events.jsonl\", jsonlreplay.Options{CreateDir: true})\nif err != nil {\n    return err\n}\ndefer w.Close()\n\nev, err := w.AppendText(\"started\", \"work\")\n\nevents, err := jsonlreplay.Replay(w.Path(), 0, 50, jsonlreplay.ReadOptions{})\nhi, err := jsonlreplay.MaxSeq(w.Path(), jsonlreplay.ReadOptions{})\n\nbatch, highSeq, err := jsonlreplay.Poll(ctx, w.Path(), hi, 2*time.Second, 50, jsonlreplay.ReadOptions{}, 0)\n```\n\n## Custom JSON shape\n\nEach line is one JSON object. Include a numeric **`seq`** so replay and polling (`sinceSeq`, `Poll`, `MaxSeq`) can resume where you left off—the rest of the fields are up to you.\n\n### Raw JSON (`AppendJSON` / `ReplayRaw`)\n\nUse when your events are not the built-in `Event` type:\n\n```go\nline, err := w.AppendJSON(json.RawMessage(`{\"type\":\"order.created\",\"id\":\"42\"}`))\n// → {\"type\":\"order.created\",\"id\":\"42\",\"seq\":1}\n\nrows, err := jsonlreplay.ReplayRaw(path, since, 50, jsonlreplay.ReadOptions{})\nfor _, row := range rows {\n    var order OrderEvent\n    json.Unmarshal(row, \u0026order)\n}\n```\n\n`ReadAllRaw`, `OpenRawIter`, and `NextRaw` stream bytes without decoding into `Event`.\n\n### Typed records (`AppendAs` + `Codec`)\n\n```go\ntype Row struct {\n    Seq    int64  `json:\"seq\"`\n    Action string `json:\"action\"`\n}\ngot, err := jsonlreplay.AppendAs(w, Row{Action: \"login\"})\n```\n\n`Options.Codec` defaults to `EventCodec` (`encoding/json`). Implement `Codec` for custom encoding (protobuf JSON, redaction, versioning wrappers).\n\n### Built-in `Event` (convenience)\n\n`Append`, `AppendText`, and `AppendData` use `kind` / `text` / `data` — best for agent/tool transcripts and simple logs.\n\n| Approach | When |\n| --- | --- |\n| `Event` + `AppendText` | Tool summaries, chatty agent logs |\n| `AppendJSON` | Arbitrary JSON, metrics blobs, API audit rows |\n| `AppendAs` + custom struct | Strongly typed domain events |\n| `Codec` | Non-standard encoding while keeping seq/replay machinery |\n\n## Rotation\n\nDefault: `SingleRotator` archives to `path+\".1\"` when `MaxFileBytes` is exceeded. Implement `Rotator` for dated segments (`.2025-05-31`), tiered archives, or object-store offload:\n\n```go\ntype Rotator interface {\n    MaybeRotate(path string, maxBytes int64, lineLen int) (rotated bool, err error)\n    ScanPaths(path string) []string // active + archives, for MaxSeq / NextSeq\n}\n```\n\nSet `Options.Rotator` and `ReadOptions.Rotator` to the same implementation so append and replay agree on segments.\n\n\n## Writer API\n\n| Function | Purpose |\n| --- | --- |\n| `Open(path, opts)` | Open or create log; resume `seq` from existing file |\n| `Append(ev)` | Append event (assigns `seq` / `time` when empty) |\n| `AppendText(kind, text)` | Shorthand text event |\n| `AppendData(kind, data)` | JSON-marshal `data` into `data` field |\n| `AppendJSON(line)` | Append any JSON object; assigns `seq` when missing |\n| `AppendAs(w, v)` | Marshal via `Codec`, inject `seq`, append |\n| `Close()` | Close file |\n\n`Writer` is safe for concurrent `Append` calls — sequence numbers are assigned under a mutex.\n\n## Read API\n\n| Function | Purpose |\n| --- | --- |\n| `MaxSeq(path, ro)` | Highest `seq` in the active file and `path+\".1\"` when present |\n| `NextSeq(path, ro)` | Next `seq` for append (1 on empty file) |\n| `ReadAll(path, ro)` | Load all events from the active file |\n| `Replay(path, sinceSeq, limit, ro)` | Stream replay: `seq \u003e sinceSeq`, optional cap (single pass) |\n| `ReplayRaw(path, sinceSeq, limit, ro)` | Replay as raw JSON bytes per line |\n| `ReadAllRaw(path, ro)` | Load active file as `[][]byte` |\n| `OpenReplayIter` / `Next` / `Close` | Iterator replay without loading the full log |\n| `OpenRawIter` / `NextRaw` / `Close` | Iterator over raw JSON lines |\n| `Poll(ctx, path, sinceSeq, timeout, limit, ro, interval)` | Wait for new `seq`, then replay |\n| `FilterReplay(all, sinceSeq, limit)` | In-memory pagination |\n\n## Options\n\n**Writer (`Options`)**\n\n- `MaxLineBytes` — cap encoded line size (default 4 MiB)\n- `MaxFileBytes` — rotate active file to `path+\".1\"` before append when over cap (0 disables)\n- `CorruptLines` — `CorruptSkip` (default) or `CorruptError` when scanning on open\n- `Durability` — `DurabilityWrite` (default), `DurabilityFlush`, or `DurabilityFsync`\n- `Clock` — inject time for tests (`Event.Time` when empty)\n- `FileMode` — created file mode (default `0644`)\n- `CreateDir` — `MkdirAll` parent directories with `0755` before open\n- `Codec` — marshal/unmarshal for `AppendAs` (default `EventCodec`)\n- `Rotator` — archive policy (default `SingleRotator` → `path+\".1\"`)\n\n**Reader (`ReadOptions`)**\n\n- `MaxLineBytes`, `CorruptLines` — same semantics while replaying\n- `Rotator` — archive paths scanned for `MaxSeq` / `NextSeq`\n\n## Durability\n\n| Mode | Behavior |\n| --- | --- |\n| `DurabilityWrite` | Returns after `Write` (may lose recent lines on crash) |\n| `DurabilityFlush` / `DurabilityFsync` | `Sync` after each successful append |\n\n**Rotation:** only the active `path` is replayed. `NextSeq` / `MaxSeq` also scan `path+\".1\"` so sequence numbers stay continuous after rotation.\n\n## Development\n\nLefthook and golangci-lint are pinned in `go.mod` as **tools** (dev-only; not library dependencies). Install git hooks once per clone:\n\n```bash\nmake install-hooks\n```\n\nThat runs `go tool lefthook install`. Hooks and `make lint` use `go tool golangci-lint` from the same `go.mod` pins. CI runs `./scripts/check.sh` (no lefthook required).\n\n```bash\nmake check\nmake test\nmake lint\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrandonkramer%2Fjsonlreplay","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrandonkramer%2Fjsonlreplay","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrandonkramer%2Fjsonlreplay/lists"}