Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs to 2021 edition, test #577

Merged
merged 2 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Change Log

## [Unreleased]
* Migrate to 2021 edition and minor cleanups by @nyurik in https://github.com/rust-lang/log/pull/580
* Use inline format args by @nyurik in https://github.com/rust-lang/log/pull/577

## [0.4.20] - 2023-07-11

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ pub fn shave_the_yak(yak: &mut Yak) {
loop {
match find_a_razor() {
Ok(razor) => {
info!("Razor located: {}", razor);
info!("Razor located: {razor}");
yak.shave(razor);
break;
}
Err(err) => {
warn!("Unable to locate a razor: {}, retrying", err);
warn!("Unable to locate a razor: {err}, retrying");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion rfcs/0296-structured-logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ fn log_record(w: impl Write, r: &Record) -> io::Result<()> {
// Write each key-value pair on a new line
record
.key_values()
.for_each(|k, v| writeln!("{}: {}", k, v))?;
.for_each(|k, v| writeln!("{k}: {v}"))?;

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions src/kv/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ pub(crate) mod tests {

impl<'v> Visit<'v> for Extract {
fn visit_any(&mut self, value: Value) -> Result<(), Error> {
unimplemented!("unexpected value: {:?}", value)
unimplemented!("unexpected value: {value:?}")
}

fn visit_u64(&mut self, value: u64) -> Result<(), Error> {
Expand All @@ -989,7 +989,7 @@ pub(crate) mod tests {

impl<'v> Visit<'v> for Extract<'v> {
fn visit_any(&mut self, value: Value) -> Result<(), Error> {
unimplemented!("unexpected value: {:?}", value)
unimplemented!("unexpected value: {value:?}")
}

fn visit_borrowed_str(&mut self, value: &'v str) -> Result<(), Error> {
Expand Down
28 changes: 14 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@
//!
//! ### Examples
//!
//! ```edition2018
//! ```
//! # #[derive(Debug)] pub struct Yak(String);
//! # impl Yak { fn shave(&mut self, _: u32) {} }
//! # fn find_a_razor() -> Result<u32, u32> { Ok(1) }
//! use log::{info, warn};
//!
//! pub fn shave_the_yak(yak: &mut Yak) {
//! info!(target: "yak_events", "Commencing yak shaving for {:?}", yak);
//! info!(target: "yak_events", "Commencing yak shaving for {yak:?}");
//!
//! loop {
//! match find_a_razor() {
//! Ok(razor) => {
//! info!("Razor located: {}", razor);
//! info!("Razor located: {razor}");
//! yak.shave(razor);
//! break;
//! }
//! Err(err) => {
//! warn!("Unable to locate a razor: {}, retrying", err);
//! warn!("Unable to locate a razor: {err}, retrying");
//! }
//! }
//! }
Expand All @@ -92,7 +92,7 @@
//! with your log records. If we take the example from before, we can include
//! some additional context besides what's in the formatted message:
//!
//! ```edition2018
//! ```
//! # use serde::Serialize;
//! # #[derive(Debug, Serialize)] pub struct Yak(String);
//! # impl Yak { fn shave(&mut self, _: u32) {} }
Expand Down Expand Up @@ -160,7 +160,7 @@
//! logs all messages at the [`Error`][level_link], [`Warn`][level_link] or
//! [`Info`][level_link] levels to stdout:
//!
//! ```edition2018
//! ```
//! use log::{Record, Level, Metadata};
//!
//! struct SimpleLogger;
Expand Down Expand Up @@ -193,7 +193,7 @@
//! provide a function that wraps a call to [`set_logger`] and
//! [`set_max_level`], handling initialization of the logger:
//!
//! ```edition2018
//! ```
//! # use log::{Level, Metadata};
//! # struct SimpleLogger;
//! # impl log::Log for SimpleLogger {
Expand Down Expand Up @@ -223,7 +223,7 @@
//! identical to `set_logger` except that it takes a `Box<Log>` rather than a
//! `&'static Log`:
//!
//! ```edition2018
//! ```
//! # use log::{Level, LevelFilter, Log, SetLoggerError, Metadata};
//! # struct SimpleLogger;
//! # impl log::Log for SimpleLogger {
Expand Down Expand Up @@ -688,7 +688,7 @@ impl<'a> MaybeStaticStr<'a> {
/// The following example shows a simple logger that displays the level,
/// module path, and message of any `Record` that is passed to it.
///
/// ```edition2018
/// ```
/// struct SimpleLogger;
///
/// impl log::Log for SimpleLogger {
Expand Down Expand Up @@ -845,7 +845,7 @@ impl<'a> Record<'a> {
///
/// # Examples
///
/// ```edition2018
/// ```
/// use log::{Level, Record};
///
/// let record = Record::builder()
Expand All @@ -860,7 +860,7 @@ impl<'a> Record<'a> {
///
/// Alternatively, use [`MetadataBuilder`](struct.MetadataBuilder.html):
///
/// ```edition2018
/// ```
/// use log::{Record, Level, MetadataBuilder};
///
/// let error_metadata = MetadataBuilder::new()
Expand Down Expand Up @@ -1011,7 +1011,7 @@ impl<'a> Default for RecordBuilder<'a> {
///
/// # Examples
///
/// ```edition2018
/// ```
/// use log::{Record, Level, Metadata};
///
/// struct MyLogger;
Expand Down Expand Up @@ -1065,7 +1065,7 @@ impl<'a> Metadata<'a> {
///
/// # Example
///
/// ```edition2018
/// ```
/// let target = "myApp";
/// use log::{Level, MetadataBuilder};
/// let metadata = MetadataBuilder::new()
Expand Down Expand Up @@ -1315,7 +1315,7 @@ pub fn set_boxed_logger(logger: Box<dyn Log>) -> Result<(), SetLoggerError> {
///
/// # Examples
///
/// ```edition2018
/// ```
/// use log::{error, info, warn, Record, Level, Metadata, LevelFilter};
///
/// static MY_LOGGER: MyLogger = MyLogger;
Expand Down
22 changes: 11 additions & 11 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
///
/// # Examples
///
/// ```edition2018
/// ```
/// use log::{log, Level};
///
/// # fn main() {
Expand Down Expand Up @@ -65,14 +65,14 @@ macro_rules! log {
///
/// # Examples
///
/// ```edition2018
/// ```
/// use log::error;
///
/// # fn main() {
/// let (err_info, port) = ("No connection", 22);
///
/// error!("Error: {} on port {}", err_info, port);
/// error!(target: "app_events", "App Error: {}, Port: {}", err_info, 22);
/// error!("Error: {err_info} on port {port}");
/// error!(target: "app_events", "App Error: {err_info}, Port: {port}");
/// # }
/// ```
#[macro_export]
Expand All @@ -89,14 +89,14 @@ macro_rules! error {
///
/// # Examples
///
/// ```edition2018
/// ```
/// use log::warn;
///
/// # fn main() {
/// let warn_description = "Invalid Input";
///
/// warn!("Warning! {}!", warn_description);
/// warn!(target: "input_events", "App received warning: {}", warn_description);
/// warn!("Warning! {warn_description}!");
/// warn!(target: "input_events", "App received warning: {warn_description}");
/// # }
/// ```
#[macro_export]
Expand All @@ -113,7 +113,7 @@ macro_rules! warn {
///
/// # Examples
///
/// ```edition2018
/// ```
/// use log::info;
///
/// # fn main() {
Expand All @@ -139,7 +139,7 @@ macro_rules! info {
///
/// # Examples
///
/// ```edition2018
/// ```
/// use log::debug;
///
/// # fn main() {
Expand All @@ -164,7 +164,7 @@ macro_rules! debug {
///
/// # Examples
///
/// ```edition2018
/// ```
/// use log::trace;
///
/// # fn main() {
Expand Down Expand Up @@ -195,7 +195,7 @@ macro_rules! trace {
///
/// # Examples
///
/// ```edition2018
/// ```
/// use log::Level::Debug;
/// use log::{debug, log_enabled};
///
Expand Down
22 changes: 22 additions & 0 deletions tests/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@ fn named_args() {
all_log_macros!(target: "my_target", "hello {world}", world = "world",);
}

#[test]
fn inlined_args() {
let world = "world";

for lvl in log::Level::iter() {
log!(lvl, "hello {world}");
log!(lvl, "hello {world}",);

log!(target: "my_target", lvl, "hello {world}");
log!(target: "my_target", lvl, "hello {world}",);

log!(lvl, "hello {world}");
log!(lvl, "hello {world}",);
}

all_log_macros!("hello {world}");
all_log_macros!("hello {world}",);

all_log_macros!(target: "my_target", "hello {world}");
all_log_macros!(target: "my_target", "hello {world}",);
}

#[test]
fn enabled() {
for lvl in log::Level::iter() {
Expand Down