Skip to main content

Crate objectstore_log

Crate objectstore_log 

Source
Expand description

Logging macros and subscriber initialization for Objectstore.

This crate provides three things:

  1. Re-exports of [tracing] macros for structured logging — use them qualified as objectstore_log::info!(). Never import the macros; always qualify at the call site.
  2. LoggingConfig and LogFormat for configuring log level and output format, and (behind the init feature) an init function to wire up a tracing-subscriber stack. When built with the sentry feature, init also attaches Sentry tracing layers if the Sentry client has already been initialized.
  3. Custom level macros (error!, warn!, etc.) that extend their tracing equivalents with an optional !<error> first argument for ergonomic error field attachment, plus event_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 DEBUG level. See event! for full syntax.
error
Logs a message at ERROR level. See event! 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 INFO level. See event! for full syntax.
trace
Logs a message at TRACE level. See event! for full syntax.
warn
Logs a message at WARN level. See event! for full syntax.

Structs§

FormatParseError
The logging format parse error.
Level
Describes the level of verbosity of a span or event.
LevelFilter
A filter comparable to a verbosity Level.
LoggingConfig
Logging configuration.

Enums§

LogFormat
Log output format.

Functions§

ensure_log_error
Logs error via the tracing subscriber if one is configured, or prints to stderr otherwise.
init
Initializes the global tracing subscriber with structured logging.