hyperlane-plugin-logger 23.0.0

A logging plugin for the Hyperlane framework, writing the log of a server to the console, to a file, or to both.
Documentation
use super::*;

/// The configuration of the logger.
#[derive(Clone)]
pub struct LoggerConfig {
    /// The highest level that is written.
    pub(crate) level: LevelFilter,
    /// The file the log is appended to, when there is one.
    pub(crate) file: Option<String>,
    /// Whether formatted lines are also echoed to standard output.
    pub(crate) console: bool,
    /// Output line format (plain text or structured JSON).
    pub(crate) format: LogFormat,
    /// Bounded non-blocking channel capacity for background file writes.
    pub(crate) channel_capacity: usize,
    /// Optional custom extensible output sink invoked alongside built-in outputs.
    pub(crate) sink: Option<Arc<dyn LogSink>>,
}

/// Streaming plain-text `fmt::Write` adapter sanitizing control bytes directly into a reusable buffer.
pub(crate) struct PlainSanitizingWriter<'a> {
    /// Target output string buffer.
    pub(crate) out: &'a mut String,
}

/// Streaming JSON `fmt::Write` adapter escaping quotes, backslashes, and control bytes directly into a buffer.
pub(crate) struct JsonSanitizingWriter<'a> {
    /// Target output string buffer.
    pub(crate) out: &'a mut String,
}

/// The plugin that writes the log of the server.
#[derive(Clone, Copy, Debug, Default)]
pub struct LoggerPlugin;

/// The middleware that notes when a request arrived.
#[derive(Clone, Copy, Debug, Default)]
#[hyperlane::request_middleware(-120)]
pub struct RequestLogger;

/// The middleware that writes the line of an answered request.
#[derive(Clone, Copy, Debug, Default)]
#[hyperlane::response_middleware(100)]
pub struct ResponseLogger;