pub struct ScopedGuard<K: Key, F>{ /* private fields */ }Expand description
RAII guard that owns a WideEvent and emits it on drop.
The guard starts a timer on creation. On drop, it sets the duration field
(via Key::DURATION_PATH) to the elapsed milliseconds, sets the
timestamp field (via Key::TIMESTAMP_PATH) to the current time as an
RFC 3339 string in the guard’s timezone, and calls the emit function
with a reference to the event.
Implements Deref / DerefMut to WideEvent so you can call
add, add_path, inc, etc. directly on the guard.
The wide_log! macro generates a WideLogGuard that wraps this guard
and manages the thread-local / task-local pointer. Users typically
interact with WideLogGuard, not ScopedGuard directly.
Implementations§
Source§impl<K: Key, F> ScopedGuard<K, F>
impl<K: Key, F> ScopedGuard<K, F>
Sourcepub fn new_with_tz(emit_fn: F, tz: Tz) -> Self
pub fn new_with_tz(emit_fn: F, tz: Tz) -> Self
Creates a new guard with the given emit function and timezone.
The timezone is used to format the timestamp set on drop.
Methods from Deref<Target = WideEvent<K>>§
Sourcepub fn add_path<V: Into<Value<K>>>(&mut self, path: &[K], value: V)
pub fn add_path<V: Into<Value<K>>>(&mut self, path: &[K], value: V)
Set a value at a nested path. Traverses/creates intermediate objects.
pub fn inc_path(&mut self, path: &[K])
pub fn dec_path(&mut self, path: &[K])
pub fn add_n_path(&mut self, path: &[K], n: i64)
pub fn append_log_entry(&mut self, level: &'static str, message: &str)
Sourcepub fn append_log_entry_static(
&mut self,
level: &'static str,
message: &'static str,
)
pub fn append_log_entry_static( &mut self, level: &'static str, message: &'static str, )
Append a log entry with a &'static str message — zero-copy.