Sink

Trait Sink 

Source
pub trait Sink:
    SinkPropAccess
    + Sync
    + Send {
    // Required methods
    fn log(&self, record: &Record<'_>) -> Result<()>;
    fn flush(&self) -> Result<()>;

    // Provided methods
    fn should_log(&self, level: Level) -> bool { ... }
    fn flush_on_exit(&self) -> Result<()> { ... }
}
Expand description

Represents a sink

See ./examples directory for how to implement a custom sink.

Required Methods§

Source

fn log(&self, record: &Record<'_>) -> Result<()>

Logs a record.

Source

fn flush(&self) -> Result<()>

Flushes any buffered records.

Provided Methods§

Source

fn should_log(&self, level: Level) -> bool

Determines if a log message with the specified level would be logged.

Source

fn flush_on_exit(&self) -> Result<()>

Flushes any buffered records at program exit.

spdlog-rs will perform a flush for sinks in the default logger when the program exits, and the flush will be called to this method flush_on_exit instead of flush. This is because the execution context may be in the atexit callback or in the panic handler when exiting. In such a context, some operations are restricted, e.g. Thread-local Storage (TLS) may not be available in atexit callbacks.

This method calls directly to flush method by default. When users’ flush method implementation is not usable in a program exit context, users should override the implementation of this method to provide an alternative flushing implementation. See the implementation of AsyncPoolSink::flush_on_exit as an example.

For combined sinks, this method should always be overridden to propagate the information that “the program is exiting” to their sub-sinks. See the implementation of DedupSink::flush_on_exit as an example.

Implementors§

Source§

impl Sink for AndroidSink

Available on Android and crate feature native and crate feature android-ndk only.
Source§

impl Sink for AsyncPoolSink

Available on crate feature multi-thread only.
Source§

impl Sink for DedupSink

Source§

impl Sink for FileSink

Source§

impl Sink for JournaldSink

Available on Linux and crate feature native and crate feature libsystemd only.
Source§

impl Sink for RotatingFileSink

Source§

impl Sink for StdStreamSink

Source§

impl Sink for WinDebugSink

Available on Windows and crate feature native only.
Source§

impl<W> Sink for WriteSink<W>
where W: Write + Send,