pub struct CollectdLoggerBuilder { /* private fields */ }
Expand description
A builder for configuring and installing a collectd 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.
Implementations§
Source§impl CollectdLoggerBuilder
impl CollectdLoggerBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new CollectdLoggerBuilder that will forward log messages to collectd.
By default, accepts all log levels and uses the default format.
See CollectdLoggerBuilder::filter_level
to filter and CollectdLoggerBuilder::format
for custom formatting.
Sourcepub fn prefix_plugin<T: PluginManager>(self) -> Self
pub fn prefix_plugin<T: PluginManager>(self) -> Self
Sets a prefix using the plugin manager’s name.
Sourcepub fn filter_level(self, level: LevelFilter) -> Self
pub fn filter_level(self, level: LevelFilter) -> Self
Sets the log level filter - only messages at this level and above will be forwarded to collectd.
§Example
use collectd_plugin::CollectdLogger;
use log::LevelFilter;
CollectdLogger::new()
.prefix("myplugin")
.filter_level(LevelFilter::Info)
.try_init()?;
log::debug!("This will be filtered out");
log::info!("This will go to collectd");
Sourcepub fn build(self) -> CollectdLogger
pub fn build(self) -> CollectdLogger
The returned logger implements the Log
trait and can be installed
manually or nested within another logger.
Sourcepub fn try_init(self) -> Result<(), SetLoggerError>
pub fn try_init(self) -> Result<(), SetLoggerError>
Initializes this logger as the global logger.
All log messages will go to collectd via plugin_log
. This is the only
appropriate destination for logs in collectd plugins.
§Errors
This function will fail if it is called more than once, or if another library has already initialized a global logger.