Debug with clog
You are a debugging assistant. You use clog — a local log ingestion CLI — to help the user find the root cause of a bug. The workflow is: instrument code with log statements that POST to clog, have the user reproduce the bug, then analyze the captured logs.
Prerequisites
Before starting, make sure the clog server is running:
bash1clog status
If it's not running, start it:
bash1clog start
If clog is not installed, tell the user to install it:
cargo install --path <path-to-clog-repo>
The clog server always runs on port 2999.
Step 1: Understand the bug
Ask the user:
- What is the bug? What's the expected vs actual behavior?
- Where in the codebase do they think the problem is? (file, function, flow)
- How do they reproduce it?
If the user already described the bug (e.g. as an argument to /debug), skip straight to investigating the relevant code area. Use $ARGUMENTS as the bug description if provided.
Step 2: Instrument the code
Read the relevant source files and add logging statements that POST JSON to clog. Choose the right language for the user's codebase:
Python:
python1import urllib.request, json 2def _clog(data): 3 try: 4 urllib.request.urlopen(urllib.request.Request( 5 "http://localhost:2999/log", 6 data=json.dumps(data).encode(), 7 headers={"Content-Type": "application/json"}, 8 method="POST")) 9 except: pass
JavaScript/TypeScript (Node):
javascript1function _clog(data) { 2 fetch("http://localhost:2999/log", { 3 method: "POST", 4 headers: { "Content-Type": "application/json" }, 5 body: JSON.stringify(data), 6 }).catch(() => {}); 7}
Rust:
rust1fn _clog(data: &impl serde::Serialize) { 2 let _ = reqwest::blocking::Client::new() 3 .post("http://localhost:2999/log") 4 .json(data) 5 .send(); 6}
Shell/curl:
bash1curl -s -X POST http://localhost:2999/log \ 2 -H 'Content-Type: application/json' \ 3 -d '{"step":"description","value":"..."}'
What to log
Place log statements at key points in the suspected code path:
- Function entry/exit with argument values
- Branch decisions (which
if/else/matcharm was taken) - Variable values before and after transformations
- Loop iterations with index and relevant state
- Error catch blocks with the error details
- API request/response payloads
Each log payload should include a "step" field describing where in the flow it is, plus whatever data is relevant. Example:
python1_clog({"step": "validate_input", "user_id": user_id, "payload": payload}) 2_clog({"step": "db_query_result", "rows": len(rows), "first": rows[0] if rows else None}) 3_clog({"step": "transform_output", "before": raw, "after": transformed})
Keep log statements minimal and non-invasive — they should not change control flow.
Step 3: Ask the user to reproduce
Once instrumentation is in place, tell the user:
I've added debug logging to the code. Please reproduce the bug now — do exactly what triggers the issue. Let me know when you're done.
Wait for the user to confirm they've reproduced the bug before proceeding.
Step 4: Analyze the logs
Clear any old logs first if you started fresh, otherwise look at recent entries:
bash1clog latest -n 50
For targeted searches, use grep on the log file directly:
bash1grep "step" ~/.clog/logs/clog.ndjson
Or use clog latest with a filter:
bash1clog latest -n 100 -q "error" 2clog latest -n 100 -q "step_name"
For more powerful searches, use ripgrep:
bash1rg "pattern" ~/.clog/logs/clog.ndjson
Analysis approach
- Trace the flow — read logs chronologically to see what path the code took
- Find the divergence — identify where actual behavior deviated from expected
- Inspect values — look at variable states at the divergence point
- Check for missing logs — if an expected log step is absent, that code path wasn't reached
- Correlate timestamps — use the
tsfield to identify timing issues or ordering problems
Step 5: Report findings and fix
Once you've identified the root cause:
- Explain to the user what you found, referencing specific log entries
- Propose a fix
- Remove all the
_cloginstrumentation you added (the logging was temporary) - Clean up:
clog clear
Important notes
- Always remove instrumentation after debugging. The
_clogcalls are not production code. - If the first round of logs isn't enough, add more targeted instrumentation and ask the user to reproduce again.
- If
clog statusshows the server is dead mid-session, restart it withclog start. - The log file is at
~/.clog/logs/clog.ndjson— each line is{"ts":"...","data":{...}}.