Struct collectd_plugin::CollectdLoggerBuilder
source · pub struct CollectdLoggerBuilder { /* private fields */ }
Expand description
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 failure::Error;
use log::LevelFilter;
#[derive(Default)]
struct MyPlugin;
impl PluginManager for MyPlugin {
fn name() -> &'static str {
"myplugin"
}
fn plugins(_config: Option<&[ConfigItem]>) -> Result<PluginRegistration, Error> {
CollectdLoggerBuilder::new()
.prefix_plugin::<Self>()
.filter_level(LevelFilter::Info)
.try_init()
.expect("really the only thing that should create a logger");
unimplemented!()
}
}
Implementations§
source§impl CollectdLoggerBuilder
impl CollectdLoggerBuilder
sourcepub fn try_init(&mut self) -> Result<(), SetLoggerError>
pub fn try_init(&mut self) -> Result<(), SetLoggerError>
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.
sourcepub fn prefix_plugin<T: PluginManager>(&mut self) -> &mut Self
pub fn prefix_plugin<T: PluginManager>(&mut self) -> &mut Self
Prefixes all log messages with a plugin’s name. This is recommended to aid debugging and gain insight into collectd logs.
sourcepub fn filter_level(&mut self, level: LevelFilter) -> &mut Self
pub fn filter_level(&mut self, level: LevelFilter) -> &mut Self
sourcepub fn filter_module(&mut self, module: &str, level: LevelFilter) -> &mut Self
pub fn filter_module(&mut self, module: &str, level: LevelFilter) -> &mut Self
Trait Implementations§
source§impl Default for CollectdLoggerBuilder
impl Default for CollectdLoggerBuilder
source§fn default() -> CollectdLoggerBuilder
fn default() -> CollectdLoggerBuilder
Returns the “default value” for a type. Read more