Enum flexi_logger::WriteMode[][src]

pub enum WriteMode {
    Direct,
    BufferAndFlush,
    BufferAndFlushWith(usizeDuration),
    BufferDontFlush,
    BufferDontFlushWith(usize),
    Async,
    AsyncWith {
        bufsize: usize,
        pool_capa: usize,
        message_capa: usize,
        flush_interval: Duration,
    },
}
Expand description

Describes whether the log output should be written synchronously or asynchronously, and if and how I/O should be buffered and flushed.

Is used in Logger::write_mode.

Buffering reduces the program’s I/O overhead, and thus increases overall performance, which can become relevant if logging is used heavily. On the other hand, if logging is used with low frequency, buffering can defer the appearance of log lines significantly, so regular flushing is usually advisable with buffering.

Note that for all options except Direct you should keep the LoggerHandle alive up to the very end of your program to ensure that all buffered log lines are flushed out (which happens automatically when the LoggerHandle is dropped) before the program terminates. See here for an example.

Note further that flushing uses an extra thread (with minimal stack).

The console is a slow output device (at least on Windows). With WriteMode::Async it can happen that in phases with vast log output the log lines appear significantly later than they were written. Also, a final printing phase is possible at the end of the program when the logger handle is dropped (and all output is flushed automatically).

WriteMode::Direct (i.e. without buffering) is the slowest option with all output devices, showing that buffered I/O pays off. But it takes slightly more resources, especially if you do not suppress flushing.

Using log_to_stdout() and then redirecting the output to a file makes things faster, but is still significantly slower than writing to files directly.

Variants

Direct

Do not buffer (default).

Every log line is directly written to the output, without buffering. This allows seeing new log lines in real time, and does not need additional threads.

BufferAndFlush

Same as BufferAndFlushWith with default capacity (DEFAULT_BUFFER_CAPACITY) and default interval (DEFAULT_FLUSH_INTERVAL).

BufferAndFlushWith(usizeDuration)

Buffer and flush with given buffer capacity and flush interval.

Tuple Fields of BufferAndFlushWith

0: usize1: Duration
BufferDontFlush

Same as BufferDontFlushWith with default capacity (DEFAULT_BUFFER_CAPACITY).

BufferDontFlushWith(usize)

Buffer with given buffer capacity, but don’t flush.

This might be handy if you want to minimize I/O effort and don’t want to create the extra thread for flushing and don’t care if log lines appear with delay.

Tuple Fields of BufferDontFlushWith

0: usize
Async
This is supported on crate feature async only.

Same as AsyncWith, using default values for all parameters.

AsyncWith
This is supported on crate feature async only.

Log lines are sent through an unbounded channel to an output thread, which does the I/O, and, if log_to_file() is chosen, also the rotation and the cleanup.

Uses buffered output to reduce overhead, and a bounded message pool to reduce allocations. The log output is flushed regularly with the given interval.

See here for an example.

Fields of AsyncWith

bufsize: usize

Size of the output buffer for the file.

pool_capa: usize

Capacity of the pool for the message buffers.

message_capa: usize

Capacity of an individual message buffer.

flush_interval: Duration

The interval for flushing the output.

With Duration::ZERO flushing is suppressed.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more