Skip to content

Commit 1d4afe2

Browse files
authored
add some docs on defaulting env vars (#96)
1 parent a8da396 commit 1d4afe2

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/lib.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,30 @@
177177
//! }
178178
//! ```
179179
//!
180+
//! ## Specifying defaults for environment variables
181+
//!
182+
//! `env_logger` can read configuration from environment variables.
183+
//! If these variables aren't present, the default value to use can be tweaked with the [`Env`] type.
184+
//! The following example defaults to log `warn` and above if the `RUST_LOG` environment variable
185+
//! isn't set:
186+
//!
187+
//! ```
188+
//! #[macro_use] extern crate log;
189+
//! extern crate env_logger;
190+
//!
191+
//! use log::Level;
192+
//!
193+
//! fn main() {
194+
//! let env = env_logger::Env::default()
195+
//! .filter_or(env_logger::DEFAULT_FILTER_ENV, "warn");
196+
//!
197+
//! env_logger::Builder::from_env(env).init();
198+
//! }
199+
//! ```
200+
//!
180201
//! [log-crate-url]: https://docs.rs/log/
181202
//! [`Builder`]: struct.Builder.html
203+
//! [`Env`]: struct.Env.html
182204
183205
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
184206
html_favicon_url = "http://www.rust-lang.org/favicon.ico",

0 commit comments

Comments
 (0)