Skip to main content

Module logger

Module logger 

Source
Expand description

Centralized logging setup for the whole framework.

init installs a global tracing_subscriber once at application boot. Everything that emits tracing events then flows through it:

  • HTTP requests/responsesdoido-controller’s logging::log_requests middleware logs a request and a response line at INFO, correlated by a shared request_id.
  • ORM queriesdoido-model’s connection enables sea-orm’s SQL logging, which emits tracing events under target sqlx::query.
  • Jobs, mail, custom events — the helpers in crate::trace.

Applications configure the logger from the logger section of config/<env>.yml, deserialized into LoggerConfig and applied via init_with_config. That controls the verbosity (built from a log level or an explicit directives filter), whether output is redirected to a file, and whether sea-orm emits sql statement logs. Because sea-orm logs through this same subscriber, redirecting to a file captures SQL too.

The RUST_LOG environment variable, when set, overrides the configured verbosity (env vars win over config, matching the rest of the framework).

Structs§

LoggerConfig
Logging settings, deserialized from the logger section of config/<env>.yml.

Enums§

LogFormat
How log events are rendered.

Constants§

DEFAULT_DIRECTIVES
Default EnvFilter directives when RUST_LOG is unset.
NOISE_DIRECTIVES
Framework targets quieted below the application log level.
REQUEST_TARGET
tracing target for the “request received” event emitted by doido-controller’s logging middleware.
RESPONSE_TARGET
tracing target for the “response sent” event emitted by doido-controller’s logging middleware. LogFormat::JsonResponse isolates this target.

Functions§

directives_for_level
Builds EnvFilter directives for an application log level (e.g. info, debug, warn), appending the framework NOISE_DIRECTIVES so SQL/HTTP internals stay quiet regardless of the chosen level.
init
Installs the global tracing subscriber using RUST_LOG (or DEFAULT_DIRECTIVES) and stdout output. Idempotent and safe to call more than once.
init_with
Like init but uses default_directives when RUST_LOG is unset.
init_with_config
Installs the global tracing subscriber from a LoggerConfig: verbosity from RUST_LOG or the config’s directives, output to the config’s file when set (otherwise stdout), and rendering per the config’s format. Idempotent and safe to call more than once; only the first call takes effect.