Crate slog_retry [] [src]

A slog adapter for retrying on errors.

The slog infrastructure is very powerful and can be bent to many scenarios. Many of the loggers there may fail, for example because they log over the network ‒ like slog-json logging into a TCP stream.

The basic framework allows for three options:

  • Handle the error manually, which is uncomfortable.
  • Ignore the error, but then all the future records are lost.
  • Fuse the drain, making it explode on the first error and killing the whole application.

This crate brings an adapter that initializes the drain anew each time an error happens, adding the ability to recover from errors.

Warning

The adapter blocks the current thread on reconnects. Therefore, you want to wrap it inside slog-async and not it directly as the root drain.

Examples

#[macro_use]
extern crate slog;
extern crate slog_async;
extern crate slog_json;
extern crate slog_retry;
 
use std::net::TcpStream;
 
use slog::Drain;
 
fn main() {
    let retry = slog_retry::Retry::new(|| -> Result<_, std::io::Error> {
            let connection = TcpStream::connect("127.0.0.1:1234")?;
            Ok(slog_json::Json::default(connection))
        }, None, true)
        // Kill the application if the initial connection fails
        .unwrap()
        // Ignore if it isn't possible to log some of the messages, we'll try again
        .ignore_res();
    let async = slog_async::Async::default(retry)
        .fuse();
    let root = slog::Logger::root(async, o!());
    info!(root, "Everything is set up");
}

Structs

Error

An error when the retry adaptor fails.

Retry

The retry adapter.

Type Definitions

NewStrategy

A constructor of a new instance of a retry strategy.

Strategy

A retry strategy.