Expand description
Structured logging to Workers Logs: levels, request-scoped fields, JSON lines (Rails’ Rails.logger and tagged logging).
Every Ctx carries a Logger: in a request it is tagged
with the request’s request_id, method and path, so each line of a
request can be found together in the Workers Logs dashboard. Add fields
with Logger::with (Rails’ logger.tagged):
use axum::extract::{Path, State};
use ocre::{Ctx, Result};
async fn pay(State(ctx): State<Ctx>, Path(order_id): Path<i64>) -> Result<&'static str> {
let log = ctx.log().with("order_id", order_id);
log.info("payment started");
log.debug(format_args!("cart: {:?}", vec![1, 2])); // formatted only when debug is on
Ok("OK")
}§Levels and formats
Two Worker variables configure logging; they are read on every request, job batch and cron run (no binding call):
| Variable | Values | Default in ocre dev (debug build) | Default after ocre deploy (release build) |
|---|---|---|---|
LOG_LEVEL | debug, info, warn, error, off (warning, fatal accepted) | debug | info |
LOG_FORMAT | json, text | text | json |
json writes each line as a JavaScript object ({"level": "info", "message": "...", "request_id": "...", ...}): Workers Logs indexes every
field, so the dashboard can filter on $metadata.request_id or your own
fields. text writes INFO payment started order_id=42 request_id=...,
easier to read in the ocre dev terminal. Lines go to console.debug,
console.info, console.warn or console.error, so the level also shows
in the dashboard and in ocre logs.
Field names matching FILTERED_PARAMETERS
(password, email, token…) are written as [FILTERED], at any depth.
§Free plan
Workers Logs keeps 200,000 events a day for 3 days on the free plan
(September 2026); each request is one event plus one per line logged.
Above that, events are sampled, never billed. info in production logs
only what the app asks for; Ocre’s own per-request and SQL lines are
debug, so they cost nothing after ocre deploy. Messages passed as
format_args!(...) are only formatted when their level is on.
Structs§
- Logger
- Writes log lines with a set of fields; cheap to clone (see the module documentation).
Enums§
- Format
- How log lines are written: see the module documentation.
- Level
- Severity of a log line (Rails’
:debug,:info,:warn,:error).
Constants§
- LOG_
FORMAT - Worker variable choosing the line format:
jsonortext. - LOG_
LEVEL - Worker variable setting the lowest level logged:
debug,info,warn,errororoff.