pub struct LogBridge { /* private fields */ }Available on crate feature
log and (crate features log or tracing) only.Expand description
Routes records from the log facade into a Logger.
- Levels map one to one (
log::Level::WarnbecomesLevel::Warn, and so on). - The record’s target, file and line are preserved.
- The message’s format arguments are rendered into a reused thread-local buffer (no allocation in steady state).
- Structured key-values (
log::info!(user = "alice"; "login")) become fields. Strings, integers, floats, booleans and chars keep their type; anything else is rendered through itsDisplayimplementation when a sink serializes the record. Up to 16 key-values are collected without allocating.
§Examples
use log_io::compat::LogBridge;
use log_io::{Level, Logger};
let logger = Logger::builder().level(Level::Info).stdout_logfmt().build();
LogBridge::new(logger).install()?;
log::info!(user = "alice", attempts = 3; "login succeeded");Implementations§
Source§impl LogBridge
impl LogBridge
Sourcepub fn install(self) -> Result<(), SetLoggerError>
pub fn install(self) -> Result<(), SetLoggerError>
Install as the log crate’s global logger and set
log::max_level from the logger’s Logger::min_level, so
disabled log macros cost a single comparison.
§Errors
Returns log::SetLoggerError if a log logger is already
installed.
Trait Implementations§
Auto Trait Implementations§
impl Forget for LogBridge
impl Freeze for LogBridge
impl Move for LogBridge
impl RefUnwindSafe for LogBridge
impl Send for LogBridge
impl Sync for LogBridge
impl Unpin for LogBridge
impl UnsafeUnpin for LogBridge
impl UnwindSafe for LogBridge
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more