Skip to content

Commit aff2c2f

Browse files
committed
refactor: addapt doc comments and examples to Builder changes
1 parent 06a3c60 commit aff2c2f

File tree

6 files changed

+14
-12
lines changed

6 files changed

+14
-12
lines changed

examples/custom_format.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn main() {
2929
.write_style("MY_LOG_STYLE");
3030

3131
Builder::from_env(env)
32-
.format(|buf, record| {
32+
.build_with_format_fn(|buf, record| {
3333
// We are reusing `anstyle` but there are `anstyle-*` crates to adapt it to your
3434
// preferred styling crate.
3535
let warn_style = buf.default_level_style(log::Level::Warn);
@@ -41,7 +41,8 @@ fn main() {
4141
record.args()
4242
)
4343
})
44-
.init();
44+
.try_init()
45+
.unwrap();
4546
}
4647

4748
init_logger();

examples/syslog_friendly_format.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::io::Write;
33
fn main() {
44
match std::env::var("RUST_LOG_STYLE") {
55
Ok(s) if s == "SYSTEMD" => env_logger::builder()
6-
.format(|buf, record| {
6+
.build_with_format_fn(|buf, record| {
77
writeln!(
88
buf,
99
"<{}>{}: {}",
@@ -18,7 +18,8 @@ fn main() {
1818
record.args()
1919
)
2020
})
21-
.init(),
21+
.try_init()
22+
.unwrap(),
2223
_ => env_logger::init(),
2324
};
2425
}

src/fmt/humantime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl Formatter {
1515
///
1616
/// let mut builder = env_logger::Builder::new();
1717
///
18-
/// builder.format(|buf, record| {
18+
/// builder.build_with_format_fn(|buf, record| {
1919
/// let ts = buf.timestamp();
2020
///
2121
/// writeln!(buf, "{}: {}: {}", ts, record.level(), record.args())

src/fmt/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//!
88
//! # Formatting log records
99
//!
10-
//! The format used to print log records can be customised using the [`Builder::format`]
10+
//! The format used to print log records can be customised using the [`Builder::build_with_format_fn`]
1111
//! method.
1212
//!
1313
//! Terminal styling is done through ANSI escape codes and will be adapted to the capabilities of
@@ -25,7 +25,7 @@
2525
//!
2626
//! let mut builder = env_logger::Builder::new();
2727
//!
28-
//! builder.format(|buf, record| {
28+
//! builder.build_with_format_fn(|buf, record| {
2929
//! writeln!(buf, "{}: {}",
3030
//! record.level(),
3131
//! record.args())
@@ -125,7 +125,7 @@ impl Default for TimestampPrecision {
125125
///
126126
/// let mut builder = env_logger::Builder::new();
127127
///
128-
/// builder.format(|buf, record| writeln!(buf, "{}: {}", record.level(), record.args()));
128+
/// builder.build_with_format_fn(|buf, record| writeln!(buf, "{}: {}", record.level(), record.args()));
129129
/// ```
130130
///
131131
/// [`Write`]: std::io::Write

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@
235235
//! use std::io::Write;
236236
//!
237237
//! env_logger::builder()
238-
//! .format(|buf, record| {
238+
//! .build_with_format_fn(|buf, record| {
239239
//! writeln!(buf, "{}: {}", record.level(), record.args())
240240
//! })
241-
//! .init();
241+
//! .try_init().unwrap();
242242
//! ```
243243
//!
244244
//! See the [`fmt`] module for more details about custom formats.

src/logger.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ pub const DEFAULT_WRITE_STYLE_ENV: &str = "RUST_LOG_STYLE";
2727
/// let mut builder = Builder::from_default_env();
2828
///
2929
/// builder
30-
/// .format(|buf, record| writeln!(buf, "{} - {}", record.level(), record.args()))
3130
/// .filter(None, LevelFilter::Info)
32-
/// .init();
31+
/// .build_with_format_fn(|buf, record| writeln!(buf, "{} - {}", record.level(), record.args()))
32+
/// .try_init().unwrap();
3333
///
3434
/// error!("error message");
3535
/// info!("info message");

0 commit comments

Comments
 (0)