Logging
How the services log, how a line reaches Grafana, and how to find an error there. Every container's output goes to Loki through Promtail, and Grafana reads Loki behind the monitoring vhost. Nothing else collects logs.
What svc-ai and svc-core log (20 October 2026)
Both services configure logging in their own app/util/logger.py. svc-ai's adds correlation ids; the rule both are held to is one test, tests/test_logging.py, kept identical by tools/test_shared_modules.py:
Libraries log at WARNING and above. The root logger is at WARNING, so botocore, urllib3, httpx, langchain-aws, LiteLLM, SQLAlchemy and every other library show their warnings and errors and nothing else. Until 20 October 2026 the root logger was at DEBUG: in production, botocore logged each Bedrock request's body and session token, langchain-aws and LiteLLM each prompt and reply, and SQLAlchemy each statement with its parameters. All of it reached the container log and Loki.
LITELLM_DEBUGis still the one opt-in for a library's payloads, for a developer, by hand.The services' own loggers are all under
app, atLOG_LEVEL(INFO when unset or not a level's name). The devcontainer sets DEBUG. A logger named outsideappfails the test, because the quiet root would silence it.No log line carries what a person wrote: a request, a prompt, an answer, a search query, a tool's arguments. A line logs its size, whether there is one, or its keys. The test fails on a log call passing such a value or a slice of it. The request log names the path, not the URL, since a query string can carry a search.
The format (23 October 2026)
Every Python service writes one format:
2026-10-23 17:59:47 | WARNING | app.router.app.knowledge.router | Indexing failed (embed)
svc-core and svc-ai:
app/util/logger.py(colorlog). Records below WARNING go to stdout, WARNING and above to stderr. uvicorn's loggers use the same handlers.svc-bff and svc-auth:
logging.basicConfiginmain.py, with the same format and date format. uvicorn keeps its default there (INFO: …).Python warnings (
warnings.warn: a library's deprecation, pydantic's serializer warnings) go through logging (logging.captureWarnings) as WARNING records onpy.warnings. Before that they were written to stderr bare, over several lines, with no timestamp or level.A traceback follows its record's first line, as Python writes it.
Migrating at startup keeps this format. svc-core, svc-ai and svc-auth run Alembic in-process during the lifespan (app/migrations.py). Alembic's env.py used to call fileConfig(alembic.ini), which replaces the root logger's handlers whatever disable_existing_loggers says. From then on every line had no timestamp, went to stderr at every level, and printed WARNING as WARNI (alembic.ini's %(levelname)-5.5s), which no level parser read. app/migrations.py now sets configure_logger off and env.py honours it. The CLI the entrypoints run (alembic upgrade head) still logs in alembic.ini's format, which Promtail also reads. tests/test_logging.py runs the startup migration in a fresh interpreter and checks that the handlers and the format survive it.
From container to Grafana
Promtail (modules/monitoring/promtail/promtail-config.yml) discovers containers through the read-only Docker socket proxy and labels each line with container, service, project, image, logstream (stdout or stderr) and level. It has two jobs, split by Compose service:
| Job | Containers | One entry is… | level comes from |
|---|---|---|---|
docker | everything else, except the monitoring stack | one line | the line's own field where it has one (nginx's error log [warn], cloudflared's INF / WRN / ERR, an access line's status), else the first level keyword in it (LOG: / ERROR: for Postgres) |
Every line has a
level:debug,info,warning,error,critical, orunknownwhen nothing says. Before 23 October 2026 a line with no level had no label. "Log Rate by Level" summed those into an unlabelled series that Grafana names Value, and the level dropdown could not offer it, since it lists label values.An access line is levelled by its status (24 October 2026). nginx's, fe-core's and fe-public's access lines name no level, so every request read
unknown, orerrorwhen its URL held the word. Now a 5xx iserror, a 4xxwarningand anything elseinfo, so a failing request shows in Errors with the service's own records. A field beats a word found in the line: cloudflared'sINF … error="…"isinfo.A record is one entry. A traceback or a multi-line warning used to arrive as one entry per line, shown bottom-up in a newest-first panel, each continuation line without a level. Promtail now joins a record's lines (
multiline, after colour codes are stripped, waiting up to 3 s and at most 1,000 lines). A line that starts no record, such as a library's bareprint, joins the record before it.Loki keeps 7 days (
loki-config.yml). It also adds its owndetected_levelas structured metadata. That is not a label, and the dashboards do not read it.
tools/test_log_pipeline.py runs Promtail's regexes over each service's output the way its pipeline applies them, and checks the dashboards below. To try a pipeline change for real, run Promtail with -dry-run over a file (it prints each entry with its labels instead of sending it).
Finding an error
Grafana → CHAIN-R Container Logs (chainr-logs.json):
Errors and Warnings: how many records in the time range.
Errors by Service: when they happened, and where.
Errors: each error or critical record, newest first, with its traceback and lines wrapped.
Log Rate by Service / Log Rate by Level, and the Live Log Stream for everything, filtered by the Service and Level variables.
The Infrastructure dashboard's Recent Errors reads the same level label. It used to grep for the word "error", which found a traceback one line at a time, plus every record that merely mentioned an error.
In Explore, for example:
{project="modules", level=~"error|critical"}
{project="modules", service="svc-core", level="warning"} |= "docling"
sum by (service) (count_over_time({project="modules", level="error"}[1h]))
project="modules" is the Compose project. A level="unknown" line is one whose output names no level: start there when a service prints something that is not a log record.
Development
make logs,make logs-beand the like follow the same output in the terminal, in colour.LOG_LEVEL=DEBUG(the devcontainer's default) shows the services' own debug lines. Libraries stay at WARNING.A test that asserts on logging uses
caplogwith the logger's name (app.…). Never assert on what a person wrote; it is never logged.