pub struct Scope { /* private fields */ }Expand description
Builds a set of scope fields.
§Examples
use ash_log::*;
use std::sync::Arc;
let logger = ash_logger!(backend: Arc::new(NoopAuditBackend));
let _scope = Scope::new()
.correlation_id("req-7f3a")
.principal("alice@example.com")
.with("tenant", "acme")
.enter();
// Both events carry the correlation ID, the principal, and `tenant`.
ash_info!(logger, "handling request");
ash_audit!(logger, MethodInvocation, Success, method = "transfer");Implementations§
Source§impl Scope
impl Scope
Sourcepub fn correlation_id<S: Into<String>>(self, id: S) -> Self
pub fn correlation_id<S: Into<String>>(self, id: S) -> Self
Bind the correlation ID.
Sourcepub fn enter(self) -> ScopeGuard
pub fn enter(self) -> ScopeGuard
Activate this scope until the returned guard is dropped.
The enclosing scope, if any, becomes this one’s parent, so its fields are still visible unless shadowed.
Sourcepub fn current() -> Option<Arc<ScopeFields>>
pub fn current() -> Option<Arc<ScopeFields>>
The active scope on this thread, if any.
Sourcepub fn apply_current(event: &mut AuditEvent)
pub fn apply_current(event: &mut AuditEvent)
Apply the active scope’s fields to event, if there is one.
Sourcepub fn current_correlation_id() -> Option<String>
pub fn current_correlation_id() -> Option<String>
The active correlation ID, for stamping an outgoing request.
Trait Implementations§
Auto Trait Implementations§
impl Forget for Scope
impl Freeze for Scope
impl Move for Scope
impl RefUnwindSafe for Scope
impl Send for Scope
impl Sync for Scope
impl Unpin for Scope
impl UnsafeUnpin for Scope
impl UnwindSafe for Scope
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