Expand description
tracing-declarative — Declarative tracing initialization via tracing.toml.
§Quick start
Create a tracing.toml in your project root:
[global]
level = "info"
ansi = true
[filter]
default_level = "info"
[[appender]]
name = "stdout"
kind = "stdout"
enabled = true
[appender.formatter]
type = "logback"
pattern = "%d [%thread] %-5level %logger{36} - %msg%n"Then initialize in your main:
tracing_declarative::init().expect("tracing init failed");
tracing::info!("application started");§Configuration search path
init() looks for tracing.toml in this order:
TRACING_CONFIGenvironment variable./tracing.toml(current working directory)./tracing.toml(executable directory)
If no file is found, a built-in default is used (INFO level, stdout, default formatter).
§Feature flags
hot-reload(default) — File-watch support (unstable;tracingdoes not support re-initialization, so this is a no-op in practice).opentelemetry— OpenTelemetry OTLP trace export via HTTP/protobuf.
§Supported formatter engines
type | Syntax | Module |
|---|---|---|
"default" | tracing-subscriber built-in | formatter::default |
"logback" | logback conversion words | formatter::logback |
"log4j" | log4j PatternLayout | formatter::log4j |
Modules§
- appender
- Appender module (currently empty — logic lives in
lib.rs). Appender module — intentionally empty. - config
- Configuration structures parsed from
tracing.toml. Configuration structures parsed fromtracing.toml. - error
- Error types. Error types for tracing-config.
- formatter
- Formatter engines (default, logback, log4j). Formatter implementations.
- sampling
- Sampling / rate-limiting writer. Sampling/Rate limiting layer for tracing events.
- span_
fields - Span field capture layer (
%X{key}/%mdcsupport). Span field capture layer for%X{key}/%mdcsupport. - windows
- Windows console ANSI support. Windows console support for ANSI color escape codes.
Constants§
- CRATE_
NAME - Crate name (injected by build.rs).
- CRATE_
VERSION - Crate version (injected by build.rs).
Functions§
- init
- Initialize tracing from the default
tracing.tomlsearch path. - init_
from_ file - Initialize tracing from a specific file path.
- init_
from_ str - Initialize tracing from a TOML string.
- parse
- Parse configuration without initializing tracing.
- try_
init_ from_ str Deprecated - Try to initialize tracing from a TOML string.