From b29735781a9f0d057a9cf13eb3cadf858a6c71de Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Wed, 8 Feb 2023 17:57:01 +0900 Subject: [PATCH] chore: Update docs and examples to 2018 edition --- README.md | 7 ++----- examples/custom_default_format.rs | 3 +-- examples/custom_logger.rs | 5 +---- examples/default.rs | 3 +-- examples/filters_from_code.rs | 5 +---- examples/in_tests.rs | 5 ++--- src/lib.rs | 6 +++--- 7 files changed, 11 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index ffc15195..d4b5763d 100644 --- a/README.md +++ b/README.md @@ -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(); @@ -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 @@ -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(); diff --git a/examples/custom_default_format.rs b/examples/custom_default_format.rs index b04eb602..81a1ef41 100644 --- a/examples/custom_default_format.rs +++ b/examples/custom_default_format.rs @@ -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}; diff --git a/examples/custom_logger.rs b/examples/custom_logger.rs index ca3a4a90..e924faee 100644 --- a/examples/custom_logger.rs +++ b/examples/custom_logger.rs @@ -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"; diff --git a/examples/default.rs b/examples/default.rs index 67bb0307..9af2a6e2 100644 --- a/examples/default.rs +++ b/examples/default.rs @@ -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; diff --git a/examples/filters_from_code.rs b/examples/filters_from_code.rs index c877a442..b9e6258d 100644 --- a/examples/filters_from_code.rs +++ b/examples/filters_from_code.rs @@ -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(); diff --git a/examples/in_tests.rs b/examples/in_tests.rs index c4487cc9..1fff5c96 100644 --- a/examples/in_tests.rs +++ b/examples/in_tests.rs @@ -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 diff --git a/src/lib.rs b/src/lib.rs index 92eeea20..0d31bc8e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -184,9 +184,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(); //! } @@ -359,10 +360,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(); ///