[−][src]Struct fern::Output
Configuration for a logger output.
Methods
impl Output
[src][−]
pub fn file<T: Into<Cow<'static, str>>>(file: File, line_sep: T) -> Self
[src][−]
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"))
pub fn writer<T: Into<Cow<'static, str>>>(
writer: Box<dyn Write + Send>,
line_sep: T
) -> Self
[src][−]
writer: Box<dyn Write + Send>,
line_sep: T
) -> Self
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"))
pub fn stdout<T: Into<Cow<'static, str>>>(line_sep: T) -> Self
[src][−]
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"))
pub fn stderr<T: Into<Cow<'static, str>>>(line_sep: T) -> Self
[src][−]
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"))
pub fn sender<T: Into<Cow<'static, str>>>(
sender: Sender<String>,
line_sep: T
) -> Self
[src][−]
sender: Sender<String>,
line_sep: T
) -> Self
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)
pub fn call<F>(func: F) -> Self where
F: Fn(&Record) + Sync + Send + 'static,
[src][−]
F: Fn(&Record) + Sync + Send + 'static,
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
impl From<Dispatch> for Output
[src][+]
impl From<Box<dyn Log + 'static>> for Output
[src][+]
impl From<&'static (dyn Log + 'static)> for Output
[src][+]
impl From<File> for Output
[src][+]
impl From<Box<dyn Write + 'static + Send>> for Output
[src][+]
impl From<Stdout> for Output
[src][+]
impl From<Stderr> for Output
[src][+]
impl From<Sender<String>> for Output
[src][+]
impl From<Panic> for Output
[src][+]
impl Debug for Output
[src][+]
Auto Trait Implementations
impl Unpin for Output
impl !Sync for Output
impl Send for Output
impl !UnwindSafe for Output
impl !RefUnwindSafe for Output
Blanket Implementations
impl<T> From<T> for T
[src][+]
impl<T, U> Into<U> for T where
U: From<T>,
[src][+]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src][+]
U: Into<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src][+]
U: TryFrom<T>,
impl<T> Borrow<T> for T where
T: ?Sized,
[src][+]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src][+]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src][+]
T: 'static + ?Sized,