-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path01_basic.rs
More file actions
30 lines (24 loc) · 1.04 KB
/
Copy path01_basic.rs
File metadata and controls
30 lines (24 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//! Simplest possible ferrilog introduction.
//!
//! Shows how to initialize the logger with the builder API, log at different
//! levels, and rely on the guard for automatic cleanup.
//!
//! Run with:
//! cargo run --example 01_basic
fn main() -> std::io::Result<()> {
// Initialize the logger: output goes to stderr, minimum level is INFO.
// The returned guard automatically stops the poller and flushes on drop.
let _guard = ferrilog::builder().level(ferrilog::INFO).start()?;
// Give the current thread a name so it appears in the log header.
ferrilog::set_thread_name("main");
// INFO and above are emitted.
ferrilog::info!("hello world");
// DBG is below INFO, so this message is silently discarded.
ferrilog::debug!("debug={}", 42u32);
// Warnings and errors are always above INFO.
ferrilog::warn!("warning={}", true);
ferrilog::error!("error code={}", -1i32);
// When `_guard` goes out of scope here, the poller thread is stopped
// and all buffered output is flushed automatically.
Ok(())
}