loggify/lib.rs
1#![deny(
2 missing_docs,
3 trivial_casts,
4 trivial_numeric_casts,
5 unsafe_code,
6 unstable_features,
7 unused_import_braces,
8 unused_qualifications
9)]
10
11//!## Usage
12//!
13//!All examples can be found in the `examples` directory.
14//!
15//!### Basic
16//!
17//!The simpliest way is just to call `init`.
18//!The default log level is `Info`, so that debug and trace messages are not shown.
19//!
20//!``` rust
21//!//! examples/01_basic.rs
22//!//! # Basic usage for the logger
23//!use log::{error, warn, info, debug, trace};
24//!use loggify::Loggify;
25//!
26//!/// The default level is INFO. So debug and trace outputs are oppressed
27//!fn main() {
28//! Loggify::init().unwrap();
29//!
30//! error!("My error message");
31//! warn!("My warn message");
32//! info!("My info message");
33//! debug!("Will not be shown");
34//! trace!("Will not be shown");
35//!}
36//!```
37//!
38//!### With log level
39//!
40//!``` rust
41//!//! examples/02_log_level.rs
42//!//! Example for initializing the logger with a log level
43//!use log::{error, warn, info, debug, trace, Level};
44//!use loggify::Loggify;
45//!
46//!/// Same as the basic example with the difference that
47//!/// the logger is intialized with the debug log level.
48//!fn main() {
49//! Loggify::init_with_level(Level::Debug).unwrap();
50//!
51//! error!("My error message");
52//! warn!("My warn message");
53//! info!("My info message");
54//! debug!("My debug message");
55//! trace!("Will not be shown");
56//!}
57//!```
58//!
59//!### Log builder
60//!``` rust
61//!//! examples/03_builder.rs
62//!//! Example for initializing the logger with the LogBuilder
63//!use log::{error, warn, info, debug, trace};
64//!use loggify::LogBuilder;
65//!
66//!/// The `LogBuilder` is used to set more logger options
67//!/// This example will change the log level to Trace
68//!/// and the printed time format to time only
69//!fn main() {
70//! LogBuilder::new()
71//! .set_level(log::Level::Trace)
72//! .set_time_format(String::from("%H:%M:%S"))
73//! .build()
74//! .unwrap();
75//!
76//! error!("My error message");
77//! warn!("My warn message");
78//! info!("My info message");
79//! debug!("My debug message");
80//! trace!("My trace message");
81//!}
82//!```
83//!
84//!### Exclude targets from log
85//!
86//!``` rust
87//!//! examples/04_exclude.rs
88//!//! Example for excluding log targets from getting logged
89//!use log::{error, warn, info, debug, trace};
90//!use loggify::LogBuilder;
91//!
92//!mod example {
93//! pub mod excluded {
94//! use log::info;
95//!
96//! pub fn call_me() {
97//! info!("I will not be logged");
98//! }
99//! }
100//!
101//! pub mod included {
102//! use log::info;
103//!
104//! pub fn call_me() {
105//! info!("I will be logged");
106//! }
107//! }
108//!}
109//!
110//!/// Exmple on how to exclude specific log targets
111//!fn main() {
112//! LogBuilder::new()
113//! // this will show the log targets so that we can determine
114//! // what to exclude
115//! .set_log_target(true)
116//! // this will oppress all logs coming from example::excluded::*
117//! .add_exclude("example::excluded".to_string())
118//! .set_level(log::Level::Trace)
119//! .build()
120//! .unwrap();
121//!
122//! error!("My error message");
123//! warn!("My warn message");
124//! info!("My info message");
125//! debug!("My debug message");
126//! trace!("My trace message");
127//!
128//! // the log message of this call will not be shown
129//! example::excluded::call_me();
130//! // this log message will be shown
131//! example::included::call_me();
132//!}
133//!```
134
135mod loggify;
136mod log_builder;
137
138pub use self::loggify::Loggify;
139pub use self::log_builder::LogBuilder;