Skip to content

Commit 6cbf356

Browse files
committed
refactor: addapt doc comments and examples to Builder changes
1 parent 88313ef commit 6cbf356

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())
@@ -124,7 +124,7 @@ impl Default for TimestampPrecision {
124124
///
125125
/// let mut builder = env_logger::Builder::new();
126126
///
127-
/// builder.format(|buf, record| writeln!(buf, "{}: {}", record.level(), record.args()));
127+
/// builder.build_with_format_fn(|buf, record| writeln!(buf, "{}: {}", record.level(), record.args()));
128128
/// ```
129129
///
130130
/// [`Write`]: std::io::Write

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,10 @@
253253
//! use std::io::Write;
254254
//!
255255
//! env_logger::builder()
256-
//! .format(|buf, record| {
256+
//! .build_with_format_fn(|buf, record| {
257257
//! writeln!(buf, "{}: {}", record.level(), record.args())
258258
//! })
259-
//! .init();
259+
//! .try_init().unwrap();
260260
//! ```
261261
//!
262262
//! 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)