Add logging::Registry::insert_logger
@@ -15,6 +15,16 @@ pub struct Registry<Id> {
}
impl<Id: Clone+'static> Registry<Id> {
+ /// Binds a log name to an action on log event batches. See
+ /// `insert_closure`.
+ pub fn insert<T: 'static, F: FnMut(&Duration, &mut Vec<(Duration, Id, T)>)+'static>(
+ &mut self,
+ name: &str,
+ action: F) -> Option<Box<Any>>
+ {
+ self.insert_closure(name, action)
+ }
+
/// Binds a log name to an action on log event batches.
///
/// This method also returns any pre-installed action, rather than overwriting it
@@ -26,12 +36,21 @@ impl<Id: Clone+'static> Registry<Id> {
/// seen (likely greater or equal to the timestamp of the last event). The end of a
/// logging stream is indicated only by dropping the associated action, which can be
/// accomplished with `remove` (or a call to insert, though this is not recommended).
- pub fn insert<T: 'static, F: FnMut(&Duration, &mut Vec<(Duration, Id, T)>)+'static>(
+ pub fn insert_closure<T: 'static, F: FnMut(&Duration, &mut Vec<(Duration, Id, T)>)+'static>(
&mut self,
name: &str,
action: F) -> Option<Box<Any>>
{
let logger = Logger::<T, Id>::new(self.time.clone(), self.id.clone(), action);
+ self.insert_logger(name, logger)
+ }
+
+ /// Binds a log name to a logger.
+ pub fn insert_logger<T: 'static>(
+ &mut self,
+ name: &str,
+ logger: Logger<T, Id>) -> Option<Box<Any>>
+ {
self.map.insert(name.to_owned(), (Box::new(logger.clone()), Box::new(logger))).map(|x| x.0)
}
