//! Nursery for slog-rs //! //! This crate is forever unstable, and contains things that //! at a given moment are useful but not final. #![warn(missing_docs)] #[macro_use] extern crate slog; use slog::*; use std::result; /// `Drain` that switches destination of error /// /// Logs everything to drain `D1`, but in case of it reporting an error, /// switching to `D2`. If `D2` returns an error too, `Failover` will return /// an error. pub struct Failover { drain1: D1, drain2: D2, } impl Failover { /// Create `Failover` pub fn new(drain1: D1, drain2: D2) -> Self { Failover { drain1: drain1, drain2: drain2, } } } impl Drain for Failover where D1 : Drain, D2 : Drain { type Error = D2::Error; fn log(&self, info: &Record, logger_values: &OwnedKeyValueList) -> result::Result<(), Self::Error> { match self.drain1.log(info, logger_values) { Ok(_) => Ok(()), Err(_) => self.drain2.log(info, logger_values), } } } /// Failover logging to secondary drain on primary's failure /// /// Create `Failover` drain pub fn failover(d1: D1, d2: D2) -> Failover { Failover::new(d1, d2) }