pub struct UdpLogger { /* private fields */ }
Expand description
The UdpLogger is a control structure for logging via UDP packets.
Implementations§
Source§impl UdpLogger
impl UdpLogger
Sourcepub fn new() -> Self
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.");
Sourcepub fn env(self) -> Self
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.
Sourcepub fn with_level(self, level: LevelFilter) -> Self
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
Sourcepub fn with_module_level(self, target: &str, level: LevelFilter) -> Self
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();
Sourcepub fn with_source(self, source: &str) -> Self
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();
Sourcepub fn with_source_level(self, source: &str, level: LevelFilter) -> Self
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();
Sourcepub fn with_destination(self, destination: &str) -> Self
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();
Sourcepub fn with_destination_level(
self,
destination: &str,
level: LevelFilter,
) -> Self
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();
Sourcepub fn with_wire_fmt(self, wire_fmt: WireFmt) -> Self
pub fn with_wire_fmt(self, wire_fmt: WireFmt) -> Self
Set the wire format for logging.
Sourcepub fn init(self) -> Result<(), SetLoggerError>
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.