Loggingdoc/{zh,en}/design/logging.md

Logging

Status: 2026-11-13. Built and tested: pkg/logging, the log file and the orquelo logs command, Host and plugin instrumentation, forwarding of process-plugin logs, and the convention

Status: 2026-11-13. Built and tested: pkg/logging, the log file and the orquelo logs command, Host and plugin instrumentation, forwarding of process-plugin logs, and the convention check. Not built: shipping logs to a remote store, a follow mode for orquelo logs, and metrics. Run traces and metrics are proposed in run traces and run quality.

Problems in production are investigated mostly by code agents. An agent reads files and runs commands; it does not watch a dashboard. So the log is designed to answer three questions with one command each: what happened in this run, what went wrong recently, and which line of code wrote this record.

1. Where Logs Are

SinkFormatFor
<log.dir>/orquelo.jsonl (default state_dir/logs)JSON Lines, one record per line; rotated to orquelo.1.jsonl, orquelo.2.jsonl, ...agents and tools: orquelo logs, jq, grep
stderr of orquelo serveshort textpeople watching a terminal
yaml
1log:
2  level: info      # debug | info | warn | error; serve -debug sets debug
3  dir: logs        # relative to the configuration file
4  max_mb: 20       # rotate at this size
5  keep: 5          # rotated files kept

2. What a Record Looks Like

json
1{"time":"2026-11-13T16:18:41.808-08:00","level":"INFO","msg":"model.called",
2 "src":"internal/host/engine/caller.go:62","pid":16470,
3 "run_id":"run_2949231e3d0282a25ad6","connection":"console","conversation_id":"console","runtime":"agent",
4 "model":"openai","instance":"agent","dur_ms":4699,"tokens_in":1238,"tokens_out":89,"finish":"tool_calls"}
  • ◆msg is a stable event name, area.what, unique in the code base. Searching the code for "model.called" finds the one line that writes it; src gives the file and line directly.
  • ◆Keys come from one vocabulary (pkg/logging/keys.go): run_id, connection, conversation_id, event_id, instance, plugin, tool, call_key, model, delivery_id, question_id, dur_ms, err, err_code, and so on. A search for run_id=X finds every line about run X.
  • ◆Errors are err (text) plus err_code (the stable plugin.Error code, e.g. llm.rate_limited, feishu.230002). err is absent on success, so filtering on err finds failures only.
  • ◆Correlation comes from the context. The Host binds identities to the context once, and every record logged under it carries them:
Bound atKeys
an inbound event being routedconnection, event_id, conversation_id
a run (start, recovery, finish)run_id, connection, conversation_id, runtime
a tool calltool, call_key
a questionquestion_id
a deliverydelivery_id, run_id, connection, conversation_id
a plugin instance's loggerinstance, plugin

A process plugin logs JSON to its stderr through the same package (pkg/plugin/serve sets this up, with the call's run_id); the Host forwards each record with its own event name and src, adding the instance.

3. How an Agent Investigates

  1. A user reports a failure. Failure messages end with the run id, e.g. Sorry, something went wrong: ... (ref run_2949...).
  2. orquelo logs -c CONFIG -run run_2949... prints the run's timeline: run.created, run.started, each model.called and tool.called with durations, question.asked/question.settled, delivery.sent, run.finished with state, err, err_code.
  3. Without an id: orquelo logs -c CONFIG -level warn -since 1h, or -event delivery. for one area, or -attr delivery_id=.... -json prints raw lines for jq.
  4. src points at the code; the event name finds it with a search. The first host.started record of a process gives the version, commit, platform, configuration revision and paths.
  5. Provider failures carry the provider's id for their support: request_id from model APIs, log_id in Feishu error messages.

4. What Is Logged

AreaEvents
Host lifecyclehost.started, host.stopped, config.reloaded, control.handled
Pluginsplugin.unavailable, plugin.requirement_unavailable, process.started, process.exited, process.start_failed, process.stderr, sdk.output
Routingroute.decided (action, trigger, user), route.failed, run.created
Runsrun.started, run.finished (warn when failed, with dur_ms), run.requeued, run.panicked
Models and toolsmodel.called, tool.called, tool.refused (reason: not_found, changed, call_chain, policy, reviewer, not_approved), tool.outcome_unknown, tool.replayed (debug)
Peoplequestion.asked, question.settled, approval.reviewer_decided
Deliverydelivery.sent, delivery.retry_scheduled, delivery.failed_permanently
Agent Runtimeagent.step (debug), agent.step_limit, agent.completion_retry, agent.output_cutoff, agent.content_filtered
Providersllm.response (debug), llm.http_error, llm.network_error, llm.retry (every model plugin that uses pkg/modelhttp; the line's plugin names it), modelfiles.uploaded, modelfiles.deleted, modelfiles.abandoned (error), feishu.message_received, feishu.message_dropped

5. Safety

  • ◆Values of keys that name secrets (*secret*, *password*, *api_key*, authorization, cookie, *access_token*, token) are written as [redacted].
  • ◆String values are cut at 4 KiB with a marker of how much was cut.
  • ◆Third-party libraries log through logging.SDK, which removes URL query strings (connection URLs carry tickets).
  • ◆Message text and tool arguments are not logged at info. Ids and counts are logged instead; debug may add more.

6. Rules for Code

These rules are in AGENTS.md section 12 and checked by TestLogConventions in pkg/logging, which make check runs:

  • ◆Only pkg/logging imports log/slog; nothing imports log. Components receive a *logging.Logger; a nil logger drops everything.
  • ◆Every call is log.Info(ctx, "area.what", key, value, ...) (or Debug, Warn, Error, Log): the event is a string literal, unique in the repository; keys are literals or logging.Key* constants from the vocabulary.
  • ◆Never log secrets, message text or tool arguments at info (section 5).
  • ◆New boundary code logs its outcome: one record per external call (with dur_ms, and err on failure), one per state transition, and one per refusal with a stable reason.