pub enum WriteMode {
    Direct,
    BufferAndFlush,
    BufferAndFlushWith(usizeDuration),
    BufferDontFlush,
    BufferDontFlushWith(usize),
}
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)

Tuple Fields

0: usize

Buffer capacity.

1: Duration

Flush interval.

Buffer and flush with given buffer capacity and flush interval.

BufferDontFlush

Same as BufferDontFlushWith with default capacity (DEFAULT_BUFFER_CAPACITY).

BufferDontFlushWith(usize)

Tuple Fields

0: usize

Buffer capacity.

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.

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

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s. Read more

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait. Read more

Use this to cast from one trait object type to another. Read more

Use this to upcast a trait to one of its supertraits. Read more

Use this to cast from one trait object type to another. This method is more customizable than the dyn_cast method. Here you can also specify the “source” trait from which the cast is defined. This can for example allow using casts from a supertrait of the current trait object. Read more

Use this to cast from one trait object type to another. With this method the type parameter is a config type that uniquely specifies which cast should be preformed. Read more

Compare self to key and return true if they are equal.

Returns the argument unchanged.

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

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

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

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