pub struct ScopeFields { /* private fields */ }Expand description
Fields bound by a scope, and whatever its parent bound.
Cheap to clone: the parent chain is shared through Arc.
Implementations§
Source§impl ScopeFields
impl ScopeFields
Sourcepub fn correlation_id(&self) -> Option<&str>
pub fn correlation_id(&self) -> Option<&str>
The correlation ID bound here, or by the nearest enclosing scope.
Sourcepub fn principal(&self) -> Option<&str>
pub fn principal(&self) -> Option<&str>
The principal bound here, or by the nearest enclosing scope.
Sourcepub fn get(&self, key: &str) -> Option<&Value>
pub fn get(&self, key: &str) -> Option<&Value>
Look up one metadata value, innermost binding first.
Sourcepub fn metadata(&self) -> HashMap<String, Value>
pub fn metadata(&self) -> HashMap<String, Value>
Every metadata key visible here, with inner bindings shadowing outer.
Sourcepub fn enter(self: Arc<Self>) -> ScopeGuard
pub fn enter(self: Arc<Self>) -> ScopeGuard
Make these fields the active scope for as long as the guard lives.
Used to carry a scope onto another thread:
use ash_log::*;
let _outer = Scope::new().correlation_id("req-1").enter();
let carried = Scope::current().expect("a scope is active");
std::thread::spawn(move || {
let _inner = carried.enter();
// Events here carry `req-1`.
})
.join()
.unwrap();Sourcepub fn apply(&self, event: &mut AuditEvent)
pub fn apply(&self, event: &mut AuditEvent)
Fill any field event has not set from these bindings.
An explicit value on the event always wins: a scope supplies defaults, it does not override what a call site stated.
Trait Implementations§
Source§impl Debug for ScopeFields
impl Debug for ScopeFields
Auto Trait Implementations§
impl Forget for ScopeFields
impl Freeze for ScopeFields
impl Move for ScopeFields
impl RefUnwindSafe for ScopeFields
impl Send for ScopeFields
impl Sync for ScopeFields
impl Unpin for ScopeFields
impl UnsafeUnpin for ScopeFields
impl UnwindSafe for ScopeFields
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