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.


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.


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("")?;
        }, None, true)
        // Kill the application if the initial connection fails
        // Ignore if it isn't possible to log some of the messages, we'll try again
    let async = slog_async::Async::default(retry)
    let root = slog::Logger::root(async, o!());
    info!(root, "Everything is set up");



An error when the retry adaptor fails.


The retry adapter.

Type Definitions


A constructor of a new instance of a retry strategy.


A retry strategy.