Karyo
Documentation/ Decision records

ADR 0026: Logs are structured JSON on standard output

Karyo 2.1.1rendered at build time
On this page

Status: Accepted

Context

Karyo's application log has two readers. A developer reads it in a terminal while working. An operator, or a tool the operator runs, reads it from the container after something has gone wrong in production. The second reader needs every line to be machine-parseable, with the request's identity attached, and neither reader wants the application managing files, rotation or shipping.

Decision

  • The application writes its log to standard output and never manages log files.
  • In the prod profile the console log is JSON (quarkus-logging-json), at INFO. In dev and test it stays plain text, for reading in a terminal.
  • Every authenticated request carries three values in the logging context, set by TenantFilter: tenantId (the goods owner id, ADR 0014), userId, and correlationId - the X-Correlation-Id request header, or empty when the header is absent. Karyo does not generate a correlation id.
  • nginx writes its own access log in a custom format that blanks the query string, and the referrer, of any request carrying a credential. Both front ends receive their sign-in authorization code in the query string, and the stock format would write that code into the log.
  • No log aggregation ships. The production Compose file sends each container's standard output to the host's journald logging driver (ADR 0022), so the host journal holds the log.

Consequences

  • Any tool that reads JSON lines parses the production log without patterns, and every line of a request says who made it and for which goods owner.
  • The log survives a redeploy, on the host only. The deploy script removes the containers before starting new ones (ADR 0022), but removing a container does not remove its journal entries. They last as long as the host's journal retention allows, which the host administrator sets (infrastructure/logging/karyo-journald.conf is the checked-in policy). Nothing ships them off the host, so a lost host loses them, and they are not a durable audit archive.
  • The correlation id is also written to journal rows. A request's X-Correlation-Id reaches the journal rows it writes (ADR 0025), so it outlives the log and a redeploy.
  • Whether the logging context can leak between requests is not established. TenantFilter sets the three values and nothing removes them, and an anonymous request returns before setting them. If the context is held per thread rather than per request in this configuration, an anonymous request served on a thread that last served an authenticated one would log the earlier user's values. It has not been measured.
  • The application log has no redaction filter. Keeping secrets and tokens out of it is a matter of review, not of the pipeline.

Alternatives considered

  • A log aggregation stack - a shipper, a store and a query interface - deployed with Karyo. Not part of the deployment. Nothing records a decision against it; it has not been built.
  • Plain-text logs in production. Rejected: a plain line needs a pattern to parse, and multi-line messages break line-based tooling.
  • JSON in development and tests too. Rejected: JSON is hard to read in a terminal, so the dev and test profiles keep plain text.
  • Log files written by the application. Rejected: rotation, retention and shipping belong to whatever runs the container, not to the application.

Evidence

  • services/karyo-app/build.gradle.kts, libs.quarkus.logging.json - the JSON logging extension
  • services/karyo-app/src/main/resources/application.yaml key quarkus.log.console.json.enabled - plain text by default
  • application.yaml keys %prod quarkus.log.console.json.enabled and quarkus.log.level - JSON at INFO in prod
  • services/karyo-app/src/main/kotlin/com/karyo/app/auth/TenantFilter.kt, TenantFilter.populateMdc - the three logging-context values
  • infrastructure/docker/nginx/nginx.conf, map $args $logged_request, map $http_referer $logged_referer, log_format karyo - why the access log redacts, and the format that does it
  • infrastructure/docker/docker-compose.prod.yml, services.*.logging - every service uses the journald driver
  • infrastructure/logging/karyo-journald.conf - the host journal retention policy
  • scripts/deploy-server.sh, Stage 6: Start infrastructure (compose down) - the containers are removed on every deploy; their journal entries are not
  • Operating an installation
  • ADR 0025 - the other signals, and why the log is the one that carries a request's identity
  • ADR 0022 - the deployment the log comes from
  • ADR 0014 - what tenantId means