ringlog/
traits.rs

1// Copyright 2021 Twitter, Inc.
2// Licensed under the Apache License, Version 2.0
3// http://www.apache.org/licenses/LICENSE-2.0
4
5use std::io::{Error, Write};
6
7/// An `Output` is a logging destination, for example, standard out or a file.
8pub trait Output: Write + Send + Sync {}
9
10/// A `Drain` serves to receive log messages from a queue and flush them to an
11/// `Output`.
12pub trait Drain: Send {
13    /// Flushes log messages from the queue to the `Output` for this `Drain`.
14    /// This function must be called periodically to ensure there is capacity on
15    /// the queue for new log messages. It is recommended that this function is
16    /// called outside of any critical paths. For example, offloading to an
17    /// admin thread or dedicated logging thread.
18    fn flush(&mut self) -> Result<(), Error>;
19}