Expand description
Small, composable backend initialization for tracing.
piquel-log is intended for applications that want a straightforward
way to install a tracing backend without exposing a large custom API.
The crate enables console output by default, allows the console sink to be
disabled, and can optionally support file output and log crate
interoperability behind Cargo features.
§Quick start
use piquel_log::Logger;
Logger::new().init()?;
tracing::info!("hello from tracing");§Disable console output
use piquel_log::Logger;
Logger::new().with_console(false).init()?;§Existing subscriber stacks
If your application already builds a tracing_subscriber registry, use
Logger::build and attach the returned BackendLayer yourself.
use piquel_log::Logger;
use tracing_subscriber::{filter::LevelFilter, prelude::*, Registry};
let backend = Logger::new().build()?;
let subscriber = Registry::default().with(LevelFilter::INFO).with(backend);
let _guard = tracing::subscriber::set_default(subscriber);
tracing::info!("hello from a custom stack");§log interoperability
When the log feature is enabled, Logger::with_log_bridge can install
tracing_log::LogTracer during Logger::init so that log records are
re-emitted as tracing events.
use piquel_log::Logger;
Logger::new().with_log_bridge(true).init()?;
log::warn!("bridged from log");§Feature matrix
- default: console backend only
Logger::with_console(false): disable the console sinkfile: configurable file outputLogger::add_file_backend(...): add a file backend at runtimestore: queryable in-memory log storageLogger::add_store_backend(...): add a store backend at runtimelog: explicitlogtotracingbridge duringinitfull: enablesfile,log, andstore
§Queryable log store
The store feature enables a thread-safe append-only in-memory backend
that captures structured log entries for later querying.
use piquel_log::{LogFilter, LogLevel, LogStore, Logger};
let store = LogStore::new();
Logger::new()
.with_console(false)
.with_store(store.clone())
.init()?;
tracing::warn!(target: "app::db", user = "alice", "slow query");
let entries = store.query(
&LogFilter::new()
.with_max_level(LogLevel::Warn)
.with_target_prefix("app::"),
);
assert_eq!(entries.len(), 1);§Non-goals for v0.1
- target allowlists or message filters
- file rotation or retention policies
- exposing individual internal sink/layer types
§Runtime backend updates
A Logger can keep the same backend layer attached while adding new
sinks later. For example, a file backend can be added after startup:
use piquel_log::{FileConfig, Logger};
let logger = Logger::new();
logger.init()?;
logger.add_file_backend(FileConfig::new("logs"))?;
tracing::info!("also written to the file backend");Structs§
- Backend
Layer - Public tracing layer produced by
crate::Logger::build. - File
Config file - File output configuration.
- LogEntry
store - A captured structured log event.
- LogField
store - A captured structured log field.
- LogFilter
store - Builder-style filter for querying a
LogStore. - LogStore
store - Thread-safe append-only in-memory log store.
- Logger
- Builder and runtime handle for the crate’s tracing backend.
Enums§
- Build
Error - Errors returned while constructing backend components.
- Init
Error - Errors returned while installing the backend globally.
- LogLevel
- Severity level of a log entry.