#![doc(html_root_url = "https://docs.rs/tracing-subscriber/0.1.3")]
#![warn(
missing_debug_implementations,
missing_docs,
rust_2018_idioms,
unreachable_pub
)]
#![cfg_attr(
test,
deny(
missing_debug_implementations,
missing_docs,
rust_2018_idioms,
unreachable_pub,
bad_style,
const_err,
dead_code,
improper_ctypes,
legacy_directory_ownership,
non_shorthand_field_patterns,
no_mangle_generic_items,
overflowing_literals,
path_statements,
patterns_in_fns_without_body,
plugin_as_library,
private_in_public,
safe_extern_statics,
unconditional_recursion,
unions_with_drop_fields,
unused,
unused_allocation,
unused_comparisons,
unused_parens,
while_true
)
)]
use tracing_core::span::Id;
#[macro_use]
macro_rules! try_lock {
($lock:expr) => {
try_lock!($lock, else return)
};
($lock:expr, else $els:expr) => {
match $lock {
Ok(l) => l,
Err(_) if std::thread::panicking() => $els,
Err(_) => panic!("lock poisoned"),
}
};
}
pub mod filter;
#[cfg(feature = "fmt")]
pub mod fmt;
pub mod layer;
pub mod prelude;
pub mod reload;
pub(crate) mod sync;
pub(crate) mod thread;
#[cfg(feature = "env-filter")]
#[allow(deprecated)]
pub use filter::{EnvFilter, Filter};
pub use layer::Layer;
#[cfg(feature = "fmt")]
pub use fmt::Subscriber as FmtSubscriber;
use std::default::Default;
#[derive(Debug)]
pub struct CurrentSpan {
current: thread::Local<Vec<Id>>,
}
impl CurrentSpan {
pub fn new() -> Self {
Self {
current: thread::Local::new(),
}
}
pub fn id(&self) -> Option<Id> {
self.current.with(|current| current.last().cloned())?
}
pub fn enter(&self, span: Id) {
self.current.with(|current| current.push(span));
}
pub fn exit(&self) {
self.current.with(|current| {
let _ = current.pop();
});
}
}
impl Default for CurrentSpan {
fn default() -> Self {
Self::new()
}
}
mod sealed {
pub trait Sealed<A = ()> {}
}