[![github]](https://github.com/rnag/sensible-env-logger) [![crates-io]](https://crates.io/crates/sensible-env-logger) [![docs-rs]](https://docs.rs/sensible-env-logger)
[github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github
[crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust
[docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K
A simple logger, optionally configured via environment variables which
writes to standard error with nice colored output for log levels.
It sets up logging with "sensible" defaults that make it ideal for
running *[examples]* and *[tests]* on a crate of choice.
[examples]: http://xion.io/post/code/rust-examples.html
[tests]: https://doc.rust-lang.org/book/ch11-01-writing-tests.html
## Usage
Even though it has `env` in the name, the `sensible-env-logger`
requires minimal configuration and setup to use:
```
#[macro_use] extern crate log;
fn main() {
sensible_env_logger::init!();
trace!("a trace example");
debug!("deboogging");
info!("such information");
warn!("o_O");
error!("boom");
}
```
Run the program and you should see all the log output for your crate.
Alternatively, run the program with the environment variables that control
the log level for *your* crate as well as *external* crates explicitly set,
like `RUST_LOG=debug` and `GLOBAL_RUST_LOG=error`.
## Defaults
The defaults can be setup by calling `init!()` or `try_init!()` at the start
of the program.
## Examples
You can check out sample usage of this crate in the [examples/](https://github.com/rnag/sensible-env-logger/tree/main/examples)
folder in the project repo on GitHub.
## Readme Docs
You can find the crate's readme documentation on the
[crates.io] page, or alternatively in the [`README.md`] file on the GitHub project repo.
[crates.io]: https://crates.io/crates/sensible-env-logger
[`README.md`]: https://github.com/rnag/sensible-env-logger
## Enable logging
This crate uses [pretty_env_logger] and [env_logger] internally, so the
same ways of enabling logs through an environment variable are supported.
The `sensible_env_logger` crate re-exports these crates, through the
`pretty` and `env` namespaces respectively.
[pretty_env_logger]: https://docs.rs/pretty_env_logger
[env_logger]: https://docs.rs/env_logger