Struct UdpLogger

Source
pub struct UdpLogger { /* private fields */ }
Expand description

The UdpLogger is a control structure for logging via UDP packets.

Implementations§

Source§

impl UdpLogger

Source

pub fn new() -> Self

Initializes the global logger with a UdpLogger instance with default log level set to Level::Trace.

§Examples
use udp_logger_rs::{UdpLogger, warn};

UdpLogger::new().env().init().unwrap();
warn!("This is an example message.");
Source

pub fn env(self) -> Self

Simulates env_logger behavior, which enables the user to choose log level by setting a RUST_LOG environment variable. This will use the default level set by with_level if RUST_LOG is not set or can’t be parsed as a standard log level.

Source

pub fn with_level(self, level: LevelFilter) -> Self

Set the ‘default’ log level.

You can override the default level for specific modules and their sub-modules using with_module_level

Source

pub fn with_module_level(self, target: &str, level: LevelFilter) -> Self

Override the log level for some specific modules.

This sets the log level of a specific module and all its sub-modules. When both the level for a parent module as well as a child module are set, the more specific value is taken. If the log level for the same module is specified twice, the resulting log level is implementation defined.

§Examples

Silence an overly verbose crate:

use udp_logger_rs::UdpLogger;
use log::LevelFilter;

UdpLogger::new().with_module_level("chatty_dependency", LevelFilter::Warn).init().unwrap();

Disable logging for all dependencies:

use udp_logger_rs::UdpLogger;
use log::LevelFilter;

UdpLogger::new()
    .with_level(LevelFilter::Off)
    .with_module_level("my_crate", LevelFilter::Info)
    .init()
    .unwrap();
Source

pub fn with_source(self, source: &str) -> Self

Override the default source socket.

This sets the default source socket, which otherwise defaults to “127.0.0.1:4000”.

§Examples

Log from UDP port “127.0.0.1:4444”

use udp_logger_rs::UdpLogger;

UdpLogger::new()
    .with_source("127.0.0.1:4444")
    .init()
    .unwrap();
Source

pub fn with_source_level(self, source: &str, level: LevelFilter) -> Self

Provide a level specific source address.

This sets the source address, for log messages matching the level.

§Examples

Log from UDP port “127.0.0.1:4001” all Info log messages. Trace and Debug messages will log from the default source address. If with_source_level() for Warn or Error aren’t set, those levels will also send from “127.0.0.1:4001”.

use udp_logger_rs::UdpLogger;
use log::LevelFilter;

UdpLogger::new()
    .with_source_level("127.0.0.1:4001", LevelFilter::Info)
    .init()
    .unwrap();
Source

pub fn with_destination(self, destination: &str) -> Self

Override the default destination address.

This sets the default destination address, which otherwise defaults to “127.0.0.1:4010”.

§Examples

Log to UDP port “127.0.0.1:4040”

use udp_logger_rs::UdpLogger;

UdpLogger::new()
    .with_destination("127.0.0.1:4040")
    .init()
    .unwrap();
Source

pub fn with_destination_level( self, destination: &str, level: LevelFilter, ) -> Self

Provide a level specific destination address.

This sets the destination address, for log messages matching the level.

§Examples

Log to UDP port “127.0.0.1:4040” all Info log messages. Trace and Debug messages will send to the default destination address. If with_destination_level() for Warn or Error aren’t set, those levels will also send to “127.0.0.1:4040”.

use udp_logger_rs::UdpLogger;
use log::LevelFilter;
UdpLogger::new()
    .with_destination_level("127.0.0.1:4040", LevelFilter::Info)
    .init()
    .unwrap();
Source

pub fn with_wire_fmt(self, wire_fmt: WireFmt) -> Self

Set the wire format for logging.

Source

pub fn init(self) -> Result<(), SetLoggerError>

‘Init’ the actual logger, instantiate it and configure it, this method MUST be called in order for the logger to be effective.

Trait Implementations§

Source§

impl Debug for UdpLogger

Source§

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

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

impl Default for UdpLogger

Source§

fn default() -> Self

See this

Source§

impl Log for UdpLogger

Source§

fn enabled(&self, metadata: &Metadata<'_>) -> bool

Determines if a log message with the specified metadata would be logged. Read more
Source§

fn log(&self, record: &Record<'_>)

Logs the Record. Read more
Source§

fn flush(&self)

Flushes any buffered records. Read more

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> 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, 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.