Skip to content

Commit

Permalink
Merge pull request #577 from nyurik/fmt-docs
Browse files Browse the repository at this point in the history
Update docs to 2021 edition, test
  • Loading branch information
KodrAus committed Nov 19, 2023
2 parents b7c4f6f + 6403cea commit cc2a3e0
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 30 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
@@ -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
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
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
Expand Up @@ -983,7 +983,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 @@ -1005,7 +1005,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
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 @@ -164,7 +164,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 @@ -197,7 +197,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 @@ -227,7 +227,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 @@ -698,7 +698,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 @@ -855,7 +855,7 @@ impl<'a> Record<'a> {
///
/// # Examples
///
/// ```edition2018
/// ```
/// use log::{Level, Record};
///
/// let record = Record::builder()
Expand All @@ -870,7 +870,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 @@ -1021,7 +1021,7 @@ impl<'a> Default for RecordBuilder<'a> {
///
/// # Examples
///
/// ```edition2018
/// ```
/// use log::{Record, Level, Metadata};
///
/// struct MyLogger;
Expand Down Expand Up @@ -1075,7 +1075,7 @@ impl<'a> Metadata<'a> {
///
/// # Example
///
/// ```edition2018
/// ```
/// let target = "myApp";
/// use log::{Level, MetadataBuilder};
/// let metadata = MetadataBuilder::new()
Expand Down Expand Up @@ -1325,7 +1325,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
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
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

0 comments on commit cc2a3e0

Please sign in to comment.