From cc011a8c92ab44939b181f28f4724f6f1118e1b8 Mon Sep 17 00:00:00 2001 From: Sam Clements Date: Sat, 18 Mar 2023 20:05:37 +0000 Subject: [PATCH] Rename with_custom_timestamps to with_timestamp_format --- examples/timestamps_format.rs | 2 +- src/lib.rs | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/examples/timestamps_format.rs b/examples/timestamps_format.rs index 66714ad..6a737a0 100644 --- a/examples/timestamps_format.rs +++ b/examples/timestamps_format.rs @@ -4,7 +4,7 @@ use time::macros::format_description; fn main() { SimpleLogger::new() .env() - .with_custom_timestamps(format_description!("[year]-[month]-[day] [hour]:[minute]:[second]")) + .with_timestamp_format(format_description!("[year]-[month]-[day] [hour]:[minute]:[second]")) .init() .unwrap(); diff --git a/src/lib.rs b/src/lib.rs index 393ddf7..67cf122 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -82,7 +82,7 @@ pub struct SimpleLogger { #[cfg(feature = "timestamps")] timestamps: Timestamps, #[cfg(feature = "timestamps")] - timeformat: Option<&'static [FormatItem<'static>]>, + timestamps_format: Option<&'static [FormatItem<'static>]>, /// Whether to use color output or not. /// @@ -115,7 +115,7 @@ impl SimpleLogger { timestamps: Timestamps::Utc, #[cfg(feature = "timestamps")] - timeformat: None, + timestamps_format: None, #[cfg(feature = "colored")] colors: true, @@ -270,7 +270,9 @@ impl SimpleLogger { self } - /// Custom timestamps format + /// Control the format used for timestamps. + /// + /// Without this, a default format is used depending on the timestamps type. /// /// The syntax for the format_description macro can be found in the /// [`time` crate book](https://time-rs.github.io/book/api/format-description.html). @@ -279,14 +281,14 @@ impl SimpleLogger { /// simple_logger::SimpleLogger::new() /// .with_level(log::LevelFilter::Debug) /// .env() - /// .with_custom_timestamps(time::macros::format_description!("[year]-[month]-[day] [hour]:[minute]:[second]")) + /// .with_timestamp_format(time::macros::format_description!("[year]-[month]-[day] [hour]:[minute]:[second]")) /// .init() /// .unwrap(); /// ``` #[must_use = "You must call init() to begin logging"] #[cfg(feature = "timestamps")] - pub fn with_custom_timestamps(mut self, timeformat: &'static [FormatItem<'static>]) -> SimpleLogger { - self.timeformat = Some(timeformat); + pub fn with_timestamp_format(mut self, format: &'static [FormatItem<'static>]) -> SimpleLogger { + self.timestamps_format = Some(format); self } @@ -451,20 +453,20 @@ impl Log for SimpleLogger { "behaviour. See the time crate's documentation for more information. ", "(https://time-rs.github.io/internal-api/time/index.html#feature-flags)" )) - .format(&self.timeformat.unwrap_or(TIMESTAMP_FORMAT_OFFSET)) + .format(&self.timestamps_format.unwrap_or(TIMESTAMP_FORMAT_OFFSET)) .unwrap() ), Timestamps::Utc => format!( "{} ", OffsetDateTime::now_utc() - .format(&self.timeformat.unwrap_or(TIMESTAMP_FORMAT_UTC)) + .format(&self.timestamps_format.unwrap_or(TIMESTAMP_FORMAT_UTC)) .unwrap() ), Timestamps::UtcOffset(offset) => format!( "{} ", OffsetDateTime::now_utc() .to_offset(offset) - .format(&self.timeformat.unwrap_or(TIMESTAMP_FORMAT_OFFSET)) + .format(&self.timestamps_format.unwrap_or(TIMESTAMP_FORMAT_OFFSET)) .unwrap() ), } @@ -628,10 +630,10 @@ mod test { #[test] #[cfg(feature = "timestamps")] #[allow(deprecated)] - fn test_with_timeformat() { + fn test_with_timestamps_format() { let builder = - SimpleLogger::new().with_custom_timestamps(time::macros::format_description!("[hour]:[minute]:[second]")); - assert!(builder.timeformat.is_some()); + SimpleLogger::new().with_timestamp_format(time::macros::format_description!("[hour]:[minute]:[second]")); + assert!(builder.timestamps_format.is_some()); } #[test]