Logging
- Introduction
- Configuration
- Writing log messages
- Request context
- Errors and panics
- Framework log lines
- Recipes
- Sending logs elsewhere
- Troubleshooting logging
Introduction
To help you understand what's happening inside your application when something goes wrong, dust-framework provides structured logging out of the box. You may write log messages to standard error, daily log files, or both, formatted as plain text or JSON. dust-framework automatically tags every log entry with the request, command, or job that produced it so you can trace a single operation through busy production logs.
You write log messages using the tracing crate's macros. Because dust-framework builds on tracing, every crate in your dependency tree that uses tracing (including packages and SQLx) writes to the same channels in the same format.
Configuration
A new application's .env file configures dust-framework to write info messages and above to standard error. dust-framework doesn't write log files unless you enable the daily channel.
LOG_CHANNEL=stderr
LOG_LEVEL=infodust-framework reads these environment variables when configuring logging:
| Variable | What it sets | Default |
|---|---|---|
LOG_LEVEL, or RUST_LOG |
The level of messages to write | info |
LOG_FORMAT |
The format: text or json |
text |
LOG_CHANNEL |
The channels to write to, such as stderr,daily |
stderr |
LOG_DAILY_LEVEL, LOG_STDERR_LEVEL, LOG_STDOUT_LEVEL |
A channel's own level | LOG_LEVEL |
LOG_DAILY_DAYS |
How many days of files the daily channel keeps, or 0 to keep all of them |
14 |
Log levels
The log level controls which messages dust-framework records: trace, debug, info, warn, or error. dust-framework writes messages at the configured level and above, so info records info, warn, and error messages. To disable logging entirely, set the level to off.
You may also set different levels per module using tracing's filter syntax. For example, this filter enables debug logs for your application while keeping SQLx at warn:
LOG_LEVEL=info,app=debug,sqlx=warnRUST_LOG accepts the same filter syntax. If both variables are set, RUST_LOG takes precedence, so a RUST_LOG exported in your shell overrides the LOG_LEVEL in .env.
Formats
The text format writes one human-readable line per message, making it easy to read in your terminal during local development. The json format writes one JSON object per line, which works well in production when a log aggregator collects and indexes your fields:
LOG_FORMAT=jsonEach JSON log entry is written on a single line. It starts with the entry's time in UTC, its level (trace, debug, info, warning, or error), its message, and its target, the module that logged it. The request, command, scheduled task, tick, job, or workflow that wrote the entry follows as an object of its own, such as request or job, so log aggregators can query paths like request.path, job.queue, or workflow.step. The entry's own fields are under fields, and the context values you add are under context. This example is formatted across multiple lines for readability:
{ "time": "2026-11-25T15:02:58.476885Z", "level": "info", "message": "Order shipped", "target": "app::orders", "request": { "id": "4bf92f…", "method": "POST", "path": "/orders/42/ship", "route": "/orders/{order}/ship" }, "fields": { "order.id": 42 }}A command, scheduled task, tick, job, or workflow names itself with name, such as "job": {"name": "podcasts.process", "queue": "podcasts", …} or "workflow": {"name": "orders.fulfil", "run": "…", "step": "charge", "attempt": 1}. On DUST Cloud, the dust-cloud-socket channel sends these same lines to Cloud's Logs page, and a request's object also carries Cloud's request ID as cloud_request_id. When OpenTelemetry tracing is enabled, JSON lines also include trace_id and span_id.
Channels
Channels control where dust-framework writes your logs:
| Channel | Destination |
|---|---|
stderr |
Standard error, where process managers and containers collect logs. The default. |
stdout |
Standard output. |
daily |
A daily rotating file in storage/logs, such as dust.2026-10-04.log. |
To write to more than one channel at once, separate the channel names with commas in LOG_CHANNEL.
Channel levels and formats
By default, LOG_LEVEL and LOG_FORMAT apply to every channel. To give a specific channel a different minimum level, set LOG_DAILY_LEVEL, LOG_STDERR_LEVEL, or LOG_STDOUT_LEVEL.
If you want to keep a local copy of warnings and errors, add daily to LOG_CHANNEL in your .env file. This configuration keeps info messages and above on standard error but saves only warnings and errors to disk:
LOG_CHANNEL=stderr,daily
LOG_LEVEL=info
LOG_DAILY_LEVEL=warnTo give a channel its own format, configure your channels in a src/config/logging.rs config file. For example, this configuration keeps stderr as text while writing daily files as JSON:
// src/config/logging.rsuse dust::config::logging::{LogChannel, LogFormat, Logging};use dust::config::{self, Env};#[config::section]fn logging(env: &Env) -> Logging { Logging { channels: vec![ LogChannel::stderr(), LogChannel::daily().level("warn").format(LogFormat::Json), ], ..Logging::from_env(env) }}Declare the module in src/config/mod.rs with mod logging;. Channels configured in code replace LOG_CHANNEL and ignore the LOG_<CHANNEL>_LEVEL variables, so specify each channel's level with .level(...) as shown above.
Writing log messages
You may write log messages from anywhere in your application using tracing's macros. There is one macro for each log level:
tracing::trace!("Checking the post's tags");tracing::debug!("Looking up the user");tracing::info!("Post published");tracing::warn!("The mail provider is slow");tracing::error!("The welcome email couldn't be sent");Each message automatically includes the context of the active request, command, or job, so you don't need to log the request ID or path manually.
Structured fields
When a log message refers to a specific record such as a post or user, pass its IDs as structured fields rather than interpolating them into the message string. For example, this handler logs each post a user publishes:
use dust::model::update;use dust::prelude::*;use crate::models::{Post, User};pub async fn publish( Authenticated(user): Authenticated<User>, mut post: Post,) -> dust::Result<Redirect> { update!(post { published_at: dust::now() }).await?; tracing::info!(post.id = post.id, user.id = user.id, "Post published"); Ok(Redirect::back())}In text format, the fields appear after the message. In json format, each field becomes a key of the entry's fields object so your log aggregator can search for every event related to post 42:
INFO request{id=4bf92f… method=POST path=/posts/42/publish route=/posts/{post}/publish}: app::http::handlers::posts: Post published post.id=42 user.id=7Structured fields accept numbers, strings, and booleans directly. To log another type using its Display or Debug implementation, prefix the field with % (for Display) or ? (for Debug). Without a prefix, types such as Timestamp won't compile:
tracing::warn!(%user.email, ?user.email_verified_at, "The welcome email bounced");Request context
Because your application handles many requests concurrently, log lines from different requests are interleaved. To help you trace a single request, dust-framework runs every request inside a request span containing the request's id, method, path, and route. Every log line written during that request inherits those fields, whether it comes from your application or a package:
INFO request{id=4bf92f3577b34da6a3ce929d0e0e4736 method=GET path=/users/1 route=/users/{user}}: app::users: Looking up the userWhen the request finishes, dust-framework also writes a summary line recording its status and duration. For a streamed response, download, or event stream, dust-framework writes that line after the last chunk is sent so the duration covers the entire response. If the client disconnects before the response finishes, dust-framework logs the status as 499.
Request IDs
Every response includes its request ID in the X-Request-Id header, so when a user reports an error, you can search your logs for that ID. If a request already arrives with an X-Request-Id header (for example, from a load balancer), dust-framework preserves it. To read the request ID inside a handler, take a RequestId argument:
use dust::http::RequestId;pub async fn show(id: RequestId) -> String { format!("Your request was {id}")}Commands, jobs, and scheduled tasks
Work running outside an HTTP request also receives a span. Every console command runs inside a command span that records the command's name:
INFO command{command=reports:generate}: app::reports: Generating the monthly reportLong-running commands such as serve, schedule:work, and queue:work don't wrap their entire lifetime in a single command span. Instead, each individual request, scheduled task, or queued job they execute runs in its own span: a scheduled_task span records the task's description, and a job span records the job's ID, name, connection, queue, and attempt.
Adding context
Sometimes every log entry written during a request should include shared information, such as the current tenant in a multi-tenant application. Any context value you add with dust::context::add is automatically attached to every subsequent log entry in that request, including reported errors. In text format, context fields appear after the message's fields; in json format, they appear under the entry's context object:
INFO request{id=4bf92f… method=POST path=/posts/42/publish route=/posts/{post}/publish}: app::http::handlers::posts: Post published post.id=42 user.id=7 tenant="acme"To store a context value without writing it to your logs, use add_hidden instead.
Errors and panics
The error handler logs every 5xx server failure at the error level. The entry's message is the error's own message, and its fields record the error's type, source location, and request context, along with its chain of causes when it has any. When a handler panics, the log entry includes the file and line where the panic occurred:
ERROR request{id=… method=GET path=/reports}: dust::errors: No such file or directory (os error 2) type="core::dust::error::Error" location=src/http/handlers/reports.rs:42:31
ERROR request{id=… method=GET path=/reports}: dust::errors: panic at src/http/handlers/reports.rs:42:9: the disk is full type="dust::errors::panic::Panic" location=src/http/handlers/reports.rs:42:9In json format, the error's type, location, and causes are under the entry's error object instead of its fields:
{"time": "2026-11-25T15:02:58.476885Z", "level": "error", "message": "the report couldn't be read", "target": "dust::errors", "error": {"type": "core::dust::error::Error", "location": "src/http/handlers/reports.rs:42:31", "causes": ["No such file or directory (os error 2)"]}, "request": {"id": "4bf92f…", "method": "GET", "path": "/reports", "route": "/reports"}}The error handler only logs 5xx failures. Client errors such as 404 or failed validation are expected outcomes and don't produce error log entries. To exclude a specific server error from your logs as well, ignore its type.
Framework log lines
dust-framework logs its internal activity under dust:: targets. Most of these entries are emitted at the debug level, so they stay quiet under the default info level. To inspect them, raise a target's level in LOG_LEVEL. For example, this filter logs every database query and cache operation:
LOG_LEVEL=info,dust::cache=debug,sqlx::query=debug| Target | Level | What it logs |
|---|---|---|
dust::request |
info locally, debug otherwise |
Each completed request, including status and duration_ms |
dust::console |
debug |
Each completed console command, including exit_code and duration_ms |
dust::queue |
debug |
Each processed job, including outcome and duration_ms |
dust::workflow |
warn |
Each failed workflow step attempt that will be retried, including run, step, and error |
dust::http::client |
debug |
Each completed outgoing request, including status or error and duration_ms |
dust::cache |
debug |
Each key the cache reads, writes, or removes |
dust::redis |
debug |
Each Redis command, without its arguments |
dust::mail |
debug |
Each email sent by a mailer |
dust::view |
debug |
Each rendered view, including duration_ms |
sqlx::query |
debug |
Each database statement (statements slower than one second log at warn) |
Request lines log at info only while APP_ENV is local, so you can watch requests in your terminal as you develop. In production, your hosting platform's access logs typically already record each request, so dust-framework logs these lines at debug to avoid writing every request twice. If nothing in front of your application keeps access logs, you may turn the lines back on:
LOG_LEVEL=info,dust::request=debugRecipes
These are the configurations applications reach for most often. Each one is a change to .env, so it takes effect on the next start.
Keep a local file of warnings and errors, and send everything to standard error:
LOG_CHANNEL=stderr,daily
LOG_LEVEL=info
LOG_DAILY_LEVEL=warn
LOG_DAILY_DAYS=14Write one JSON line per event for a log collector:
LOG_CHANNEL=stdout
LOG_FORMAT=json
LOG_LEVEL=infoWatch your own code closely without the database's chatter:
LOG_LEVEL=info,app=debug,sqlx=warnSee each request and each slow query while reproducing a problem:
RUST_LOG=info,dust::request=debug,sqlx=query=debug cargo run -- serveRUST_LOG in the shell beats LOG_LEVEL in .env, so the last recipe is a one-off and does not change the application's configuration.
Sending logs elsewhere
While channels write to standard output or local files, you may also want to forward errors to an external tracker that alerts your team. Any service that integrates with tracing can receive your logs through a tracing layer registered with with_logging in src/app.rs. Custom layers receive events at every level by default, so attach a filter with with_filter from tracing_subscriber.
A service provider may also register a layer via app.logging() in its register method. To learn more about registering layers from a package, check out the package development guide's section on logging. If you'd like to export distributed traces instead of log messages, check out the tracing guide.
Sentry
To send errors to Sentry, add the sentry crate (with its tracing feature) and tracing-subscriber to your Cargo.toml. Then register Sentry's tracing layer for errors and initialize Sentry in a boot hook in src/app.rs:
// src/app.rsuse dust::prelude::*;use tracing_subscriber::Layer;use tracing_subscriber::filter::LevelFilter;Application::configure() .with_logging(|logging, _| { logging.layer( sentry::integrations::tracing::layer().with_filter(LevelFilter::ERROR), ); }) .with_services(|app| { app.singleton(|_| async { Ok(sentry::init(sentry::ClientOptions::new())) }); }) .booted(|app| async move { app.resolve::<sentry::ClientInitGuard>().await.map(drop) })Initialize Sentry in the boot hook rather than in main. dust-framework loads .env into the process environment right before booting, so sentry::init picks up the SENTRY_DSN defined there. Storing the ClientInitGuard in the container ensures Sentry flushes any pending events when your application exits, which keeps errors from short-lived console commands from being dropped.
Because the error handler logs every server failure at the error level, failures arrive in Sentry alongside errors you log yourself. Note that Sentry's tracing layer doesn't automatically include values you added to the request context. To include those context values (or forward failures to a service without a tracing layer), register an error reporter and read them with context::all().
Troubleshooting logging
| Symptom | What to check |
|---|---|
| No lines at all | LOG_LEVEL is not off, the channel list is not empty, and the process's stderr is captured somewhere. |
Only info lines, no debug |
The default level is info; set LOG_LEVEL=debug or name the target, as in app=debug. |
A RUST_LOG value seems ignored |
RUST_LOG wins over LOG_LEVEL; unset it in the shell to let .env apply. |
No storage/logs files |
The daily channel is not in LOG_CHANNEL; the default is stderr only. |
| JSON lines are not valid JSON | A custom layer wrote to the same destination, or a message contains a raw newline; let tracing format the line rather than printing it yourself. |
| A field is missing from JSON | The value is not a number, string, or boolean and needs % or ?; a Timestamp, for example, needs %. |
| A request line is missing in production | Request lines log at debug outside local; use LOG_LEVEL=info,dust::request=debug. |
| Colors in a pipe | Set NO_COLOR=1 to turn them off, or leave FORCE_COLOR unset. |
The error handler only logs 5xx responses. A missing line for a 404 or a failed validation is expected, not a logging problem. If a 5xx has no line, check that the error's type isn't ignored.