A simple terminal logger
Add this in your Cargo.toml
:
toml
[dependencies]
logs = "*"
```rust use logs::{debug, error, info, trace, warn};
fn main() { debug!("This is a debug log"); trace!("This is a trace log"); info!("This is a info log"); warn!("This is a warn log"); error!("This is a error log"); } ```
```rust use logs::{LogConfig, debug, error};
fn main() { let mut config = Config::disable_all();
// Disable debug! output
config.debug(false);
// Allow error! output
config.error(true);
// The output of `trace!` is only displayed in debug mode
#[cfg(debug_assertions)]
config.trace(true);
// Change datetime format: [Fri Nov 27 15:56:08 2020]
config.date_format("%c").unwrap();
config.build();
debug!("This is a debug log");
error!("This is a error log");
}
```
This can be configured by reading the LOG
environment variable, which disables all output by default
```bash
export LOG='all,!debug,info,!error' ```
```rust use logs::Config;
fn main() { Config::from_env().unwrap().build(); } ```