Expand description
Logging macros and subscriber initialization for Objectstore.
This crate provides three things:
- Re-exports of [
tracing] macros for structured logging — use them qualified asobjectstore_log::info!(). Never import the macros; always qualify at the call site. LoggingConfigandLogFormatfor configuring log level and output format, and (behind theinitfeature) aninitfunction to wire up atracing-subscriberstack. When built with thesentryfeature,initalso attaches a Sentry tracing layer if the Sentry client has already been initialized.- Custom level macros (
error!,warn!, etc.) that extend theirtracingequivalents with an optional!<error>first argument for ergonomic error field attachment, plusevent_dyn!for runtime-dispatched log levels.
§Usage
§Logging macros
All standard tracing levels are available. Prefix an error expression with !! to attach it as
a typed error field without a manual cast:
let err = anyhow::anyhow!("something broke");
objectstore_log::info!("server starting");
objectstore_log::warn!(status = "degraded", "storage unavailable");
objectstore_log::error!(!!err.as_ref(), "fatal startup error");
objectstore_log::warn!(!!err.as_ref(), component = "storage", "retrying");§event_dyn! — dispatch log level at runtime
let level = Level::WARN;
objectstore_log::event_dyn!(level, "dynamic level message");
objectstore_log::event_dyn!(level, field = "value", "with fields");§Subscriber initialization (requires init feature)
ⓘ
let config = objectstore_log::LoggingConfig::default();
objectstore_log::init(&config);§Span types and span macros
Types and macros from the underlying [tracing] crate that are not re-exported individually
(such as [tracing::Span] and [tracing::debug_span!]) are accessible through the re-exported
tracing module:
use objectstore_log::tracing;
let span: tracing::Span = tracing::debug_span!("my_span");Re-exports§
pub use tracing;
Macros§
- debug
- Logs a message at
DEBUGlevel. Seeevent!for full syntax. - error
- Logs a message at
ERRORlevel. Seeevent!for full syntax. - event
- Logs a message at a given static level.
- event_
dyn - Dispatches a log event at a level determined at runtime.
- info
- Logs a message at
INFOlevel. Seeevent!for full syntax. - trace
- Logs a message at
TRACElevel. Seeevent!for full syntax. - warn
- Logs a message at
WARNlevel. Seeevent!for full syntax.
Structs§
- Format
Parse Error - The logging format parse error.
- Level
- Describes the level of verbosity of a span or event.
- Level
Filter - A filter comparable to a verbosity
Level. - Logging
Config - Logging configuration.
Enums§
- LogFormat
- Log output format.
Functions§
- ensure_
log_ error - Logs
errorvia the tracing subscriber if one is configured, or prints tostderrotherwise. - init
- Initializes the global tracing subscriber with structured logging.