LoggerOptions

Struct LoggerOptions 

Source
pub struct LoggerOptions {
    pub levels: Option<LoggerLevels>,
    pub format: Option<Arc<dyn Format<Input = LogInfo> + Send + Sync>>,
    pub level: Option<String>,
    pub transports: Option<Vec<(TransportHandle, LoggerTransport<LogInfo>)>>,
    pub channel_capacity: Option<usize>,
    pub backpressure_strategy: Option<BackpressureStrategy>,
}

Fields§

§levels: Option<LoggerLevels>§format: Option<Arc<dyn Format<Input = LogInfo> + Send + Sync>>§level: Option<String>§transports: Option<Vec<(TransportHandle, LoggerTransport<LogInfo>)>>§channel_capacity: Option<usize>§backpressure_strategy: Option<BackpressureStrategy>

Implementations§

Source§

impl LoggerOptions

Source

pub fn new() -> Self

Creates a new LoggerOptions instance with default settings.

Source

pub fn level<T: Into<String>>(self, level: T) -> Self

Sets the logging level for the logger.

§Arguments
  • level - A string slice that represents the logging level.
Source

pub fn format<F>(self, format: F) -> Self
where F: Format<Input = LogInfo> + Send + Sync + 'static,

Sets the log format for the logger.

§Arguments
  • format - The log format to be used.
Source

pub fn transport(self, transport: impl IntoLoggerTransport) -> Self

Adds a single transport to the existing list of transports.

This method is additive — it appends the provided transport to any previously added transports. Each transport is automatically wrapped in an Arc and assigned a unique [TransportHandle].

This method accepts either a raw transport or a pre-configured LoggerTransport.

§Example
use winston_rs::LoggerOptions;

// Raw transport
let options = LoggerOptions::new()
    .transport(stdout())
    .transport(FileTransport::new("app.log"));

// Pre-configured transport
let options = LoggerOptions::new()
    .transport(
        LoggerTransport::new(FileTransport::new("app.log"))
            .with_level("debug")
            .with_format(json())
    );

Each call to transport appends a new transport, allowing multiple outputs (e.g. console + file + network) to be used simultaneously.

Source

pub fn transports<I>(self, transports: I) -> Self
where I: IntoIterator, I::Item: IntoLoggerTransport,

Replaces all transports with the provided collection.

This method is not additive — it replaces any previously configured transports. Each transport must already be wrapped in an Arc and will be assigned a unique [TransportHandle].

§Example
use winston_rs::LoggerOptions;
use std::sync::Arc;

let transports = vec![
    Arc::new(stdout()),
    Arc::new(FileTransport::new("app.log")),
];
let options = LoggerOptions::new().transports(transports);

Use this method when you want to replace all existing transports instead of appending new ones. Multiple calls to .transports() will override the previous collection.

Source

pub fn levels(self, levels: HashMap<String, u8>) -> Self

Sets custom logging levels for the logger.

§Arguments
  • levels - A HashMap where the key is the level name and the value is its severity.
Source

pub fn channel_capacity(self, capacity: usize) -> Self

Sets the channel capacity for the logger.

§Arguments
  • capacity - An usize that defines the capacity of the channel.
Source

pub fn backpressure_strategy(self, strategy: BackpressureStrategy) -> Self

Sets the backpressure strategy for the logger.

§Arguments
  • strategy - The backpressure strategy to apply when the channel is full.

Trait Implementations§

Source§

impl Clone for LoggerOptions

Source§

fn clone(&self) -> LoggerOptions

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LoggerOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LoggerOptions

Source§

fn default() -> Self

Provides the default configuration for LoggerOptions.

The default configuration includes:

  • A default set of logging levels.
  • The logging level set to “info”.
  • No default transports.
  • The JSON format for log entries.
  • A channel capacity of 1024.
  • A backpressure strategy set to BackpressureStrategy::Block, meaning the logger will block on overflow until space is available.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.