[−][src]Struct collectd_plugin::CollectdLoggerBuilder
Bridges the gap between collectd and rust logging. Terminology and filters methods found here are from env_logger.
It is recommended to instantiate the logger in PluginManager::plugins.
The use case of multiple rust plugins that instantiate a global logger is supported. Each plugin will have its own copy of a global logger. Thus plugins won't interefere with others and their logging.
Example
use collectd_plugin::{ConfigItem, PluginManager, PluginRegistration, CollectdLoggerBuilder}; use log::LevelFilter; use std::error; #[derive(Default)] struct MyPlugin; impl PluginManager for MyPlugin { fn name() -> &'static str { "myplugin" } fn plugins(_config: Option<&[ConfigItem]>) -> Result<PluginRegistration, Box<error::Error>> { CollectdLoggerBuilder::new() .prefix_plugin::<Self>() .filter_level(LevelFilter::Info) .try_init() .expect("really the only thing that should create a logger"); unimplemented!() } }
Methods
impl CollectdLoggerBuilder[src]
pub fn new() -> Self[src]
Initializes the log builder with defaults
pub fn try_init(&mut self) -> Result<(), SetLoggerError>[src]
Initializes the global logger with the built collectd logger.
Errors
This function will fail if it is called more than once, or if another library has already initialized a global logger.
pub fn prefix_plugin<T: PluginManager>(&mut self) -> &mut Self[src]
Prefixes all log messages with a plugin's name. This is recommended to aid debugging and gain insight into collectd logs.
pub fn filter_level(&mut self, level: LevelFilter) -> &mut Self[src]
pub fn filter_module(&mut self, module: &str, level: LevelFilter) -> &mut Self[src]
pub fn filter(&mut self, module: Option<&str>, level: LevelFilter) -> &mut Self[src]
pub fn parse(&mut self, filters: &str) -> &mut Self[src]
pub fn format<F: 'static>(&mut self, format: F) -> &mut Self where
F: Fn(&mut dyn Write, &Record) -> Result<()> + Sync + Send, [src]
F: Fn(&mut dyn Write, &Record) -> Result<()> + Sync + Send,
Sets the format function for formatting the log output.
Trait Implementations
impl Default for CollectdLoggerBuilder[src]
fn default() -> CollectdLoggerBuilder[src]
Auto Trait Implementations
impl Send for CollectdLoggerBuilder
impl Sync for CollectdLoggerBuilder
Blanket Implementations
impl<T, U> Into for T where
U: From<T>, [src]
U: From<T>,
impl<T> From for T[src]
impl<T, U> TryFrom for T where
U: Into<T>, [src]
U: Into<T>,
type Error = !
try_from)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T> Borrow for T where
T: ?Sized, [src]
T: ?Sized,
impl<T, U> TryInto for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized, [src]
T: ?Sized,