Skip to main content

ConsoleAppender

Struct ConsoleAppender 

Source
pub struct ConsoleAppender { /* private fields */ }
Expand description

Console appender that writes to stdout

Implementations§

Source§

impl ConsoleAppender

Source

pub fn new(layout: Box<dyn Layout>) -> Self

Create a new console appender with a specific layout

Examples found in repository?
examples/file_appender.rs (line 12)
8fn main() {
9    let log_path = std::env::temp_dir().join("log4rc-file-appender.log");
10
11    Logger::builder(LogLevel::Info)
12        .appender(Box::new(ConsoleAppender::new(Box::new(SimpleLayout))))
13        .appender(Box::new(
14            FileAppender::open(&log_path, Box::new(SimpleLayout))
15                .expect("failed to open log file"),
16        ))
17        .init();
18
19    log4rc::info!("Writing to console and file");
20    log4rc::error!("An error also goes to both");
21    log4rc::debug!("Filtered out at Info level");
22
23    // Read the file back to prove the messages were written to disk.
24    let mut contents = String::new();
25    std::fs::File::open(&log_path)
26        .expect("failed to reopen log file")
27        .read_to_string(&mut contents)
28        .expect("failed to read log file");
29
30    println!("\n--- Contents of {} ---", log_path.display());
31    print!("{contents}");
32    let _ = std::fs::remove_file(&log_path);
33}

Trait Implementations§

Source§

impl Appender for ConsoleAppender

Source§

fn append(&self, event: &LogEvent<'_>)

Append a log event to the output target

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.