pub struct AutoLogGuard { /* private fields */ }Expand description
Owned, non-Clone guard that emits a lifecycle log entry when dropped.
Created via OperationContext::with_auto_log. Unlike OperationContext
— which is a plain, Clone data value — this guard owns the context and
performs the suc! / fail! / cancel! log write exactly once, on drop.
§Why a separate, non-Clone type?
A drop-time side effect must not be duplicated by cloning; otherwise
attaching an armed context to an error would log the same failure twice (or
defer the log to the error’s drop). Keeping the guard non-Clone while the
data type stays Clone makes “attach as data” (err.with_context(&guard))
free of side effects.
§Example
use orion_error::OperationContext;
let ctx = OperationContext::doing("renew").with_field("gateway_id", "gw-1");
let data = ctx.clone(); // pure data copy, safe to attach to an error
let _guard = ctx.with_auto_log(); // logs once, on drop
let _ = data;Implementations§
Source§impl AutoLogGuard
impl AutoLogGuard
Sourcepub fn with_field<K, V>(self, key: K, val: V) -> Self
pub fn with_field<K, V>(self, key: K, val: V) -> Self
Builder-style field addition while keeping the guard alive.
Sourcepub fn with_meta<K, V>(self, key: K, value: V) -> Self
pub fn with_meta<K, V>(self, key: K, value: V) -> Self
Builder-style metadata addition while keeping the guard alive.
Sourcepub fn with_mod_path<S: Into<String>>(self, path: S) -> Self
pub fn with_mod_path<S: Into<String>>(self, path: S) -> Self
Builder-style module-path override while keeping the guard alive.
Sourcepub fn mark_success(&mut self)
pub fn mark_success(&mut self)
Explicitly mark the guarded operation as successful (suc!).
Sourcepub fn mark_failure(&mut self)
pub fn mark_failure(&mut self)
Keep the failure result (the default), logging fail! on drop.
Sourcepub fn into_context(self) -> OperationContext
pub fn into_context(self) -> OperationContext
Disarm the guard and return the owned, pure-data OperationContext
without emitting a log entry.
Methods from Deref<Target = OperationContext>§
pub fn context(&self) -> &CallContext
pub fn result(&self) -> &OperationResult
pub fn mod_path(&self) -> &String
pub fn action(&self) -> &Option<String>
pub fn locator(&self) -> &Option<String>
pub fn path(&self) -> &[String]
pub fn metadata(&self) -> &ErrorMetadata
pub fn with_doing<S: Into<String>>(&mut self, action: S)
pub fn with_at<S: Into<String>>(&mut self, locator: S)
Sourcepub fn set_target<S: Into<String>>(&mut self, target: S)
pub fn set_target<S: Into<String>>(&mut self, target: S)
Alias: set the target resource/operation name. The first call establishes the root target; subsequent calls only append to the path.
pub fn path_string(&self) -> Option<String>
Sourcepub fn record_field<K, V>(&mut self, key: K, val: V)
pub fn record_field<K, V>(&mut self, key: K, val: V)
Record a human-readable key-value pair into the context stack.
The entry will appear in the error’s Display output.
For typed metadata hidden from console output, use [record_meta()] instead.
Prefer with_field for chained construction.
record_field is for when you already have a mutable reference.
pub fn record<K, V>(&mut self, key: K, val: V)
Sourcepub fn record_meta<K, V>(&mut self, key: K, value: V)
pub fn record_meta<K, V>(&mut self, key: K, value: V)
Record typed metadata that is not included in Display output.
Use this for structured fields intended for serialization, snapshots, or
API responses. For user-visible context entries, use [record_field()].
Prefer with_meta for chained construction.
record_meta is for when you already have a mutable reference.
pub fn mark_suc(&mut self)
pub fn mark_cancel(&mut self)
pub fn mark_fail(&mut self)
Sourcepub fn scope(&mut self) -> OperationScope<'_>
pub fn scope(&mut self) -> OperationScope<'_>
Create a scope guard, defaulting to failure state.
Requires explicit mark_success(), mark_cancel(), or mark_fail().
Sourcepub fn scoped_success(&mut self) -> OperationScope<'_>
pub fn scoped_success(&mut self) -> OperationScope<'_>
Create a scope guard that automatically marks success on drop.
pub fn info<S: AsRef<str>>(&self, message: S)
pub fn debug<S: AsRef<str>>(&self, message: S)
pub fn warn<S: AsRef<str>>(&self, message: S)
pub fn error<S: AsRef<str>>(&self, message: S)
pub fn trace<S: AsRef<str>>(&self, message: S)
Sourcepub fn log_info<S: AsRef<str>>(&self, message: S)
pub fn log_info<S: AsRef<str>>(&self, message: S)
Alias for documentation consistency (calls the same-named method above).
pub fn log_debug<S: AsRef<str>>(&self, message: S)
pub fn log_warn<S: AsRef<str>>(&self, message: S)
pub fn log_error<S: AsRef<str>>(&self, message: S)
pub fn log_trace<S: AsRef<str>>(&self, message: S)
Trait Implementations§
Source§impl Debug for AutoLogGuard
impl Debug for AutoLogGuard
Source§impl Deref for AutoLogGuard
impl Deref for AutoLogGuard
Source§impl DerefMut for AutoLogGuard
impl DerefMut for AutoLogGuard
Source§impl Display for AutoLogGuard
impl Display for AutoLogGuard
Source§impl Drop for AutoLogGuard
impl Drop for AutoLogGuard
§impl From<&AutoLogGuard> for OperationContext
Attach an armed AutoLogGuard’s context to an error as pure data.
impl From<&AutoLogGuard> for OperationContext
Attach an armed AutoLogGuard’s context to an error as pure data.
Taking the guard by shared reference deliberately copies only the data; the
guard keeps ownership and remains the single owner responsible for the
drop-time log entry. There is intentionally no From<AutoLogGuard> (by
value): moving the guard into an error would defer/repeat its log.