Skip to main content

Loggable

Trait Loggable 

Source
pub trait Loggable {
    // Required methods
    fn log_level(&self) -> Level;
    fn log_module(&self) -> Module;
}
Expand description

Allows an error type to declare its own log severity and module routing.

Implementing this trait on a domain error type decentralizes the decision of how to categorize an error for telemetry purposes. The error itself knows best whether it represents a minor client mistake (a Warning) or a critical infrastructure failure (a Fatal). This avoids the need for a centralized match statement in the middleware every time a new error variant is added.

§Implementation contract

Implementations must be pure and infallible. They inspect &self and return a static classification. They must not allocate or perform any I/O.

§Usage

This trait is consumed by [crate::Error::into_response], which calls log_level and log_module on the top-level error before consuming it (since into_response takes self by value). The resulting values are packed into a crate::logger::Entry and placed into the response extension backpack for the logging middleware to pick up.

use webdav_server::logger::{Level, Module, Loggable};

struct MyError;

impl Loggable for MyError {
    fn log_level(&self) -> Level {
        Level::Error
    }

    fn log_module(&self) -> Module {
        Module::Api
    }
}

Required Methods§

Source

fn log_level(&self) -> Level

Returns the severity level that should be assigned to this error in the log.

Source

fn log_module(&self) -> Module

Returns the server module responsible for this error.

This value is used by the admin CLI to filter and group entries. Most domain errors return a fixed module (e.g., Module::Storage for all storage::Error variants), while the top-level crate::Error delegates to the inner error.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Loggable for webdav_server::api::error::Error

Source§

impl Loggable for webdav_server::model::error::Error

Source§

impl Loggable for webdav_server::storage::error::Error

Source§

impl Loggable for webdav_server::error::Error