Skip to content

Commit

Permalink
Merge pull request #260 from y-yagi/2018-edition
Browse files Browse the repository at this point in the history
chore: Update docs and examples to 2018 edition
  • Loading branch information
epage committed Nov 10, 2023
2 parents 6f64347 + b297357 commit 36b1508
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 23 deletions.
7 changes: 2 additions & 5 deletions README.md
Expand Up @@ -23,8 +23,7 @@ $ cargo add log env_logger
`env_logger` must be initialized as early as possible in the project. After it's initialized, you can use the `log` macros to do actual logging.

```rust
#[macro_use]
extern crate log;
use log::info;

fn main() {
env_logger::init();
Expand Down Expand Up @@ -88,9 +87,6 @@ env_logger = "0.9.0"
```

```rust
#[macro_use]
extern crate log;

fn add_one(num: i32) -> i32 {
info!("add_one called with {}", num);
num + 1
Expand All @@ -99,6 +95,7 @@ fn add_one(num: i32) -> i32 {
#[cfg(test)]
mod tests {
use super::*;
use log::info;

fn init() {
let _ = env_logger::builder().is_test(true).try_init();
Expand Down
3 changes: 1 addition & 2 deletions examples/custom_default_format.rs
Expand Up @@ -17,8 +17,7 @@ $ export MY_LOG_STYLE=never
If you want to control the logging output completely, see the `custom_logger` example.
*/

#[macro_use]
extern crate log;
use log::info;

use env_logger::{Builder, Env};

Expand Down
5 changes: 1 addition & 4 deletions examples/custom_logger.rs
Expand Up @@ -10,12 +10,9 @@ $ export MY_LOG_LEVEL='info'
If you only want to change the way logs are formatted, look at the `custom_format` example.
*/

#[macro_use]
extern crate log;

use env_logger::filter::{Builder, Filter};

use log::{Log, Metadata, Record, SetLoggerError};
use log::{info, Log, Metadata, Record, SetLoggerError};

const FILTER_ENV: &str = "MY_LOG_LEVEL";

Expand Down
3 changes: 1 addition & 2 deletions examples/default.rs
Expand Up @@ -15,8 +15,7 @@ $ export MY_LOG_STYLE=never
```
*/

#[macro_use]
extern crate log;
use log::{debug, error, info, trace, warn};

use env_logger::Env;

Expand Down
5 changes: 1 addition & 4 deletions examples/filters_from_code.rs
Expand Up @@ -2,12 +2,9 @@
Specify logging filters in code instead of using an environment variable.
*/

#[macro_use]
extern crate log;

use env_logger::Builder;

use log::LevelFilter;
use log::{debug, error, info, trace, warn, LevelFilter};

fn main() {
Builder::new().filter_level(LevelFilter::max()).init();
Expand Down
5 changes: 2 additions & 3 deletions examples/in_tests.rs
Expand Up @@ -11,13 +11,12 @@ cargo test --example in_tests
You should see the `it_does_not_work` test fail and include its log output.
*/

#[cfg_attr(test, macro_use)]
extern crate log;

fn main() {}

#[cfg(test)]
mod tests {
use log::debug;

fn init_logger() {
let _ = env_logger::builder()
// Include all events in tests
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Expand Up @@ -173,9 +173,10 @@
//! The [`Builder::is_test`] method can be used in unit tests to ensure logs will be captured:
//!
//! ```
//! # #[macro_use] extern crate log;
//! #[cfg(test)]
//! mod tests {
//! use log::info;
//!
//! fn init() {
//! let _ = env_logger::builder().is_test(true).try_init();
//! }
Expand Down Expand Up @@ -348,10 +349,9 @@ pub struct Logger {
/// # Examples
///
/// ```
/// # #[macro_use] extern crate log;
/// # use std::io::Write;
/// use env_logger::Builder;
/// use log::LevelFilter;
/// use log::{LevelFilter, error, info};
///
/// let mut builder = Builder::from_default_env();
///
Expand Down

0 comments on commit 36b1508

Please sign in to comment.