Documentation
¶
Overview ¶
Package debuglog provides a lightweight, opt-in NDJSON event logger for auditing how anchored is actually being used by the host AI tool.
The goal is observability, not telemetry: when the user wants to understand why memory tools fired (or didn't), they enable Debug.Enabled in ~/.anchored/config.yaml (or set ANCHORED_DEBUG=1) and get an append-only NDJSON file they can grep, jq, or replay.
Design rules:
- Never fail the caller. Open/Write errors are swallowed; the worst case is a missing log line, never a broken hook or MCP call.
- One JSON object per line ({ts, event, ...fields}) so the file is trivially parsable with jq -c or Python's json.loads per line.
- Append-only with O_APPEND so concurrent processes (multiple hook invocations + the MCP server) don't clobber each other; we still take a mutex per *Logger to keep individual writes intact.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Snippet ¶
Snippet truncates s to n runes, appending an ellipsis when trimmed. Use this on user-facing strings (prompt bodies, tool args) so the log doesn't balloon with multi-KB payloads.
Rune-aware (not byte-aware) on purpose: PT-BR / multilingual prompts would otherwise be cut mid-codepoint, producing invalid UTF-8 that json.Marshal silently replaces with U+FFFD — corrupting the very evidence the debug log exists to capture.
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a single-file NDJSON appender. The zero value is a valid no-op Logger; callers can safely call Event on a nil receiver.
func Open ¶
Open returns a Logger configured from cfg, with environment overrides.
Env overrides (highest precedence):
- ANCHORED_DEBUG=1|true|on → force enable
- ANCHORED_DEBUG=0|false|off → force disable
- ANCHORED_DEBUG_PATH=/path → override log file path
When disabled, Open returns a zero-value Logger that no-ops on Event so call sites stay branch-free.