Struct slog_retry::Retry
[−]
[src]
pub struct Retry<Slave, Factory> { /* fields omitted */ }
The retry adapter.
This wraps another drain and forwards log records into that. However, if the drain returns an error, it discards it and tries to create a new one and log the message into it.
It uses the retry strategy to decide how long to wait before retrying and how many times. If the retry strategy runs out of items, it gives up, returns an error and the log record is lost.
However, it is not destroyed by the error and if it is called to log another record, it tries to reconnect again (using a fresh instance of the strategy).
Warning
This adapter is synchronous and blocks during the retry attempts. Unless you provide a retry strategy with a single zero item, you don't want to use it directly. Wrap it inside slog-async, where it'll only slow down the logging thread and the channel into that thread will be used as a buffer for messages waiting to be written after the reconnect.
Methods
impl<Slave, FactoryError, Factory> Retry<Slave, Factory> where
Slave: Drain,
FactoryError: Fail + Debug,
Slave::Err: Fail + Debug,
Factory: Fn() -> Result<Slave, FactoryError>,
[src]
Slave: Drain,
FactoryError: Fail + Debug,
Slave::Err: Fail + Debug,
Factory: Fn() -> Result<Slave, FactoryError>,
pub fn new(
factory: Factory,
strategy: Option<NewStrategy>,
connect_now: bool
) -> Result<Self, Error<FactoryError, Slave::Err>>
[src]
factory: Factory,
strategy: Option<NewStrategy>,
connect_now: bool
) -> Result<Self, Error<FactoryError, Slave::Err>>
Creates a new retry adapter.
Parameters
factory
: A factory function that is used to produce new instance of the slave drain on every (re)connection attempt.strategy
: A reconnect strategy, describing how long to wait between attempts and how many attempts to make. If set toNone
a default strategy with 4 increasingly delayed attemps is used.connect_now
: Should a connection be made right away. If it is set totrue
, it may block (it uses the reconnect strategy provided) and it may return an error. If set tofalse
, the connection is made on the first logged message. No matter if connecting now or later, the first connection attempt is without waiting.
Trait Implementations
impl<Slave, FactoryError, Factory> Drain for Retry<Slave, Factory> where
Slave: Drain,
FactoryError: Fail + Debug,
Slave::Err: Fail + Debug,
Factory: Fn() -> Result<Slave, FactoryError>,
[src]
Slave: Drain,
FactoryError: Fail + Debug,
Slave::Err: Fail + Debug,
Factory: Fn() -> Result<Slave, FactoryError>,
type Ok = Slave::Ok
Type returned by this drain Read more
type Err = Error<FactoryError, Slave::Err>
Type of potential errors that can be returned by this Drain
fn log(
&self,
record: &Record,
values: &OwnedKVList
) -> Result<Self::Ok, Self::Err>
[src]
&self,
record: &Record,
values: &OwnedKVList
) -> Result<Self::Ok, Self::Err>
Handle one logging statement (Record
) Read more
fn is_enabled(&self, level: Level) -> bool
[src]
Avoid: Check if messages at the specified log level are maybe enabled for this logger. Read more
fn is_critical_enabled(&self) -> bool
[src]
Avoid: See is_enabled
fn is_error_enabled(&self) -> bool
[src]
Avoid: See is_enabled
fn is_warning_enabled(&self) -> bool
[src]
Avoid: See is_enabled
fn is_info_enabled(&self) -> bool
[src]
Avoid: See is_enabled
fn is_debug_enabled(&self) -> bool
[src]
Avoid: See is_enabled
fn is_trace_enabled(&self) -> bool
[src]
Avoid: See is_enabled
fn map<F, R>(self, f: F) -> R where
F: FnOnce(Self) -> R,
[src]
F: FnOnce(Self) -> R,
Pass Drain
through a closure, eg. to wrap into another Drain
. Read more
fn filter<F>(self, f: F) -> Filter<Self, F> where
F: FilterFn,
[src]
F: FilterFn,
Filter logging records passed to Drain
Read more
fn filter_level(self, level: Level) -> LevelFilter<Self>
[src]
Filter logging records passed to Drain
(by level) Read more
fn map_err<F, E>(self, f: F) -> MapError<Self, E> where
F: MapErrFn<Self::Err, E>,
[src]
F: MapErrFn<Self::Err, E>,
Map logging errors returned by this drain Read more
fn ignore_res(self) -> IgnoreResult<Self>
[src]
Ignore results returned by this drain Read more
fn fuse(self) -> Fuse<Self> where
Self::Err: Debug,
[src]
Self::Err: Debug,
Make Self
panic when returning any errors Read more