Skip to content

Commit b297357

Browse files
y-yagiepage
authored andcommitted
chore: Update docs and examples to 2018 edition
1 parent 85dde7d commit b297357

File tree

7 files changed

+11
-23
lines changed

7 files changed

+11
-23
lines changed

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ $ cargo add log env_logger
2323
`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.
2424

2525
```rust
26-
#[macro_use]
27-
extern crate log;
26+
use log::info;
2827

2928
fn main() {
3029
env_logger::init();
@@ -88,9 +87,6 @@ env_logger = "0.9.0"
8887
```
8988

9089
```rust
91-
#[macro_use]
92-
extern crate log;
93-
9490
fn add_one(num: i32) -> i32 {
9591
info!("add_one called with {}", num);
9692
num + 1
@@ -99,6 +95,7 @@ fn add_one(num: i32) -> i32 {
9995
#[cfg(test)]
10096
mod tests {
10197
use super::*;
98+
use log::info;
10299

103100
fn init() {
104101
let _ = env_logger::builder().is_test(true).try_init();

examples/custom_default_format.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ $ export MY_LOG_STYLE=never
1717
If you want to control the logging output completely, see the `custom_logger` example.
1818
*/
1919

20-
#[macro_use]
21-
extern crate log;
20+
use log::info;
2221

2322
use env_logger::{Builder, Env};
2423

examples/custom_logger.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@ $ export MY_LOG_LEVEL='info'
1010
If you only want to change the way logs are formatted, look at the `custom_format` example.
1111
*/
1212

13-
#[macro_use]
14-
extern crate log;
15-
1613
use env_logger::filter::{Builder, Filter};
1714

18-
use log::{Log, Metadata, Record, SetLoggerError};
15+
use log::{info, Log, Metadata, Record, SetLoggerError};
1916

2017
const FILTER_ENV: &str = "MY_LOG_LEVEL";
2118

examples/default.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ $ export MY_LOG_STYLE=never
1515
```
1616
*/
1717

18-
#[macro_use]
19-
extern crate log;
18+
use log::{debug, error, info, trace, warn};
2019

2120
use env_logger::Env;
2221

examples/filters_from_code.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22
Specify logging filters in code instead of using an environment variable.
33
*/
44

5-
#[macro_use]
6-
extern crate log;
7-
85
use env_logger::Builder;
96

10-
use log::LevelFilter;
7+
use log::{debug, error, info, trace, warn, LevelFilter};
118

129
fn main() {
1310
Builder::new().filter_level(LevelFilter::max()).init();

examples/in_tests.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ cargo test --example in_tests
1111
You should see the `it_does_not_work` test fail and include its log output.
1212
*/
1313

14-
#[cfg_attr(test, macro_use)]
15-
extern crate log;
16-
1714
fn main() {}
1815

1916
#[cfg(test)]
2017
mod tests {
18+
use log::debug;
19+
2120
fn init_logger() {
2221
let _ = env_logger::builder()
2322
// Include all events in tests

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,10 @@
184184
//! The [`Builder::is_test`] method can be used in unit tests to ensure logs will be captured:
185185
//!
186186
//! ```
187-
//! # #[macro_use] extern crate log;
188187
//! #[cfg(test)]
189188
//! mod tests {
189+
//! use log::info;
190+
//!
190191
//! fn init() {
191192
//! let _ = env_logger::builder().is_test(true).try_init();
192193
//! }
@@ -359,10 +360,9 @@ pub struct Logger {
359360
/// # Examples
360361
///
361362
/// ```
362-
/// # #[macro_use] extern crate log;
363363
/// # use std::io::Write;
364364
/// use env_logger::Builder;
365-
/// use log::LevelFilter;
365+
/// use log::{LevelFilter, error, info};
366366
///
367367
/// let mut builder = Builder::from_default_env();
368368
///

0 commit comments

Comments
 (0)