Struct fern::Output[][src]

pub struct Output(_);
Expand description

Configuration for a logger output.

Implementations

Returns a file logger using a custom separator.

If the default separator of \n is acceptable, an fs::File instance can be passed into Dispatch::chain directly.

fern::Dispatch::new().chain(std::fs::File::create("log")?)
fern::Dispatch::new().chain(fern::log_file("log")?)

Example usage (using fern::log_file):

fern::Dispatch::new().chain(fern::Output::file(fern::log_file("log")?, "\r\n"))

Returns a logger using arbitrary write object and custom separator.

If the default separator of \n is acceptable, an Box<Write + Send> instance can be passed into Dispatch::chain directly.

// Anything implementing 'Write' works.
let mut writer = std::io::Cursor::new(Vec::<u8>::new());

fern::Dispatch::new()
    // as long as we explicitly cast into a type-erased Box
    .chain(Box::new(writer) as Box<std::io::Write + Send>)

Example usage:

let writer = Box::new(std::io::Cursor::new(Vec::<u8>::new()));

fern::Dispatch::new().chain(fern::Output::writer(writer, "\r\n"))

Returns an stdout logger using a custom separator.

If the default separator of \n is acceptable, an io::Stdout instance can be passed into Dispatch::chain() directly.

fern::Dispatch::new().chain(std::io::stdout())

Example usage:

fern::Dispatch::new()
    // some unix tools use null bytes as message terminators so
    // newlines in messages can be treated differently.
    .chain(fern::Output::stdout("\0"))

Returns an stderr logger using a custom separator.

If the default separator of \n is acceptable, an io::Stderr instance can be passed into Dispatch::chain() directly.

fern::Dispatch::new().chain(std::io::stderr())

Example usage:

fern::Dispatch::new().chain(fern::Output::stderr("\n\n\n"))

Returns a mpsc::Sender logger using a custom separator.

If the default separator of \n is acceptable, an mpsc::Sender<String> instance can be passed into Dispatch:: chain() directly.

Each log message will be suffixed with the separator, then sent as a single String to the given sender.

use std::sync::mpsc::channel;

let (tx, rx) = channel();
fern::Dispatch::new().chain(tx)

Returns a logger which simply calls the given function with each message.

The function will be called inline in the thread the log occurs on.

Example usage:

fern::Dispatch::new().chain(fern::Output::call(|record| {
    // this is mundane, but you can do anything here.
    println!("{}", record.args());
}))

Trait Implementations

Formats the value using the given formatter. Read more

Creates an output logger forwarding all messages to the custom logger.

Creates an output logger forwarding all messages to the custom logger.

Creates an output logger which writes all messages to the writer with \n as the separator.

This does no buffering and it is up to the writer to do buffering as needed (eg. wrap it in BufWriter). However, flush is called after each log record.

Creates an output logger forwarding all messages to the dispatch.

Creates an output logger which writes all messages to the file with \n as the separator.

File writes are buffered and flushed once per log record.

Creates an output logger which will panic with message text for all messages.

Creates an output logger which writes all messages to the given mpsc::Sender with ‘\n’ as the separator.

All messages sent to the mpsc channel are suffixed with ‘\n’.

Creates an output logger which writes all messages to stderr with the given handle and \n as the separator.

Creates an output logger which writes all messages to stdout with the given handle and \n as the separator.

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.

Performs the conversion.

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.