pub struct ConsoleAppender { /* private fields */ }Expand description
Console appender that writes to stdout
Implementations§
Source§impl ConsoleAppender
impl ConsoleAppender
Sourcepub fn new(layout: Box<dyn Layout>) -> Self
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§
Auto Trait Implementations§
impl !RefUnwindSafe for ConsoleAppender
impl !UnwindSafe for ConsoleAppender
impl Freeze for ConsoleAppender
impl Send for ConsoleAppender
impl Sync for ConsoleAppender
impl Unpin for ConsoleAppender
impl UnsafeUnpin for ConsoleAppender
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more