From 53983e0b0e603ae672f4245a36d342068b4f0925 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Mon, 23 Nov 2026 16:17:15 +0000 Subject: [PATCH 1/3] chore!: upgrade jiff to 1.0 --- CHANGELOG.md | 1 + Cargo.toml | 2 +- appenders/fastrace/src/lib.rs | 7 +++++-- appenders/file/src/clock.rs | 20 ++++++++++---------- appenders/file/src/rolling.rs | 20 ++++++++++---------- appenders/file/src/rotation.rs | 12 ++++++------ 6 files changed, 33 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d6cfb54..22341220 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. * Bump minimum supported Rust version (MSRV) to 1.91.0. * `logforth-append-opentelemetry` upgrades `opentelemetry`, `opentelemetry-otlp` and `opentelemetry_sdk` to 0.33.1. +* Upgrade `jiff` to 1.0. ## [0.30.1] 2026-06-03 diff --git a/Cargo.toml b/Cargo.toml index c0b661b4..9a37f984 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,7 +62,7 @@ ctor = { version = "1.0.6" } fastrace = { version = "0.7" } fasyslog = { version = "1.0.0" } insta = { version = "1.43.2" } -jiff = { version = "0.2" } +jiff = { version = "1.0" } libc = { version = "0.2.162" } log = { version = "0.4.31", default-features = false } oneshot = { version = "0.2.1", default-features = false, features = ["std"] } diff --git a/appenders/fastrace/src/lib.rs b/appenders/fastrace/src/lib.rs index b4d729c5..93f25561 100644 --- a/appenders/fastrace/src/lib.rs +++ b/appenders/fastrace/src/lib.rs @@ -19,7 +19,7 @@ use std::borrow::Cow; -use jiff::Zoned; +use jiff::ZonedDateTime; use logforth_core::Diagnostic; use logforth_core::Error; use logforth_core::append::Append; @@ -65,7 +65,10 @@ impl Append for FastraceEvent { || { [ (Cow::from("level"), Cow::from(record.level().name())), - (Cow::from("timestamp"), Cow::from(Zoned::now().to_string())), + ( + Cow::from("timestamp"), + Cow::from(ZonedDateTime::now().to_string()), + ), ] .into_iter() .chain(collector.kv) diff --git a/appenders/file/src/clock.rs b/appenders/file/src/clock.rs index 9ad806dd..5309b1f9 100644 --- a/appenders/file/src/clock.rs +++ b/appenders/file/src/clock.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use jiff::Zoned; +use jiff::ZonedDateTime; #[derive(Debug)] pub enum Clock { @@ -22,16 +22,16 @@ pub enum Clock { } impl Clock { - pub fn now(&self) -> Zoned { + pub fn now(&self) -> ZonedDateTime { match self { - Clock::DefaultClock => Zoned::now(), + Clock::DefaultClock => ZonedDateTime::now(), #[cfg(test)] Clock::ManualClock(clock) => clock.now(), } } #[cfg(test)] - pub fn set_now(&mut self, now: Zoned) { + pub fn set_now(&mut self, now: ZonedDateTime) { if let Clock::ManualClock(clock) = self { clock.set_now(now); } @@ -42,20 +42,20 @@ impl Clock { #[derive(Debug)] #[cfg(test)] pub struct ManualClock { - now: Zoned, + now: ZonedDateTime, } #[cfg(test)] impl ManualClock { - pub fn new(now: Zoned) -> ManualClock { + pub fn new(now: ZonedDateTime) -> ManualClock { ManualClock { now } } - fn now(&self) -> Zoned { + fn now(&self) -> ZonedDateTime { self.now.clone() } - pub fn set_now(&mut self, now: Zoned) { + pub fn set_now(&mut self, now: ZonedDateTime) { self.now = now; } } @@ -68,11 +68,11 @@ mod tests { #[test] fn test_manual_clock_adjusting() { - let now = Zoned::from_str("2024-08-10T17:12:52+08[+08]").unwrap(); + let now = ZonedDateTime::from_str("2024-08-10T17:12:52+08[+08]").unwrap(); let mut clock = ManualClock { now: now.clone() }; assert_eq!(clock.now(), now); - let now = Zoned::from_str("2024-01-01T12:00:00+08[+08]").unwrap(); + let now = ZonedDateTime::from_str("2024-01-01T12:00:00+08[+08]").unwrap(); clock.set_now(now.clone()); assert_eq!(clock.now(), now); } diff --git a/appenders/file/src/rolling.rs b/appenders/file/src/rolling.rs index 5427be5b..69040ab7 100644 --- a/appenders/file/src/rolling.rs +++ b/appenders/file/src/rolling.rs @@ -23,7 +23,7 @@ use std::path::Path; use std::path::PathBuf; use std::str::FromStr; -use jiff::Zoned; +use jiff::ZonedDateTime; use jiff::civil::DateTime; use logforth_core::Error; use logforth_core::Trap; @@ -214,7 +214,7 @@ struct State { date_format: &'static str, rotation: Rotation, current_filesize: usize, - this_date_timestamp: Zoned, + this_date_timestamp: ZonedDateTime, next_date_timestamp: Option, max_size: Option, max_files: Option, @@ -274,7 +274,7 @@ impl State { state.current_filesize = last.metadata.len() as usize; if let Ok(mtime) = last.metadata.modified() - && let Ok(mtime) = Zoned::try_from(mtime) + && let Ok(mtime) = ZonedDateTime::try_from(mtime) { state.next_date_timestamp = state.rotation.next_date_timestamp(&mtime); state.this_date_timestamp = mtime; @@ -309,7 +309,7 @@ impl State { .map_err(|err| Error::new("failed to create log file").with_source(err)) } - fn join_date(&self, date: &Zoned, cnt: usize) -> PathBuf { + fn join_date(&self, date: &ZonedDateTime, cnt: usize) -> PathBuf { let date = date.strftime(self.date_format); let filename = match ( &self.rotation, @@ -420,7 +420,7 @@ impl State { Ok(()) } - fn rotate_log_writer(&self, now: &Zoned) -> Result { + fn rotate_log_writer(&self, now: &ZonedDateTime) -> Result { let mut renames = vec![]; for i in 1..self.max_files.map_or(usize::MAX, |n| n.get()) { let filepath = self.join_date(now, i); @@ -458,7 +458,7 @@ impl State { self.create_log_writer() } - fn refresh_writer(&self, now: &Zoned, file: &mut File) { + fn refresh_writer(&self, now: &ZonedDateTime, file: &mut File) { match self.rotate_log_writer(now) { Ok(new_file) => { if let Err(err) = file.flush() { @@ -474,7 +474,7 @@ impl State { } } - fn should_rollover_on_date(&self, date: &Zoned) -> bool { + fn should_rollover_on_date(&self, date: &ZonedDateTime) -> bool { self.next_date_timestamp .is_some_and(|ts| date.timestamp().as_millisecond() as usize >= ts) } @@ -495,7 +495,7 @@ mod tests { use std::str::FromStr; use jiff::Span; - use jiff::Zoned; + use jiff::ZonedDateTime; use rand::RngExt; use rand::distr::Alphanumeric; use tempfile::TempDir; @@ -572,7 +572,7 @@ mod tests { let max_files = NonZeroUsize::new(10).unwrap(); let temp_dir = TempDir::new().unwrap(); - let start_time = Zoned::from_str("2024-08-10T00:00:00[UTC]").unwrap(); + let start_time = ZonedDateTime::from_str("2024-08-10T00:00:00[UTC]").unwrap(); let mut writer = RollingFileWriterBuilder::new(temp_dir.as_ref(), "test_file") .rotation(rotation) .filename_suffix("log") @@ -637,7 +637,7 @@ mod tests { let total_files = 100; let temp_dir = TempDir::new().unwrap(); - let start_time = Zoned::from_str("2024-08-10T00:00:00[UTC]").unwrap(); + let start_time = ZonedDateTime::from_str("2024-08-10T00:00:00[UTC]").unwrap(); let mut writer = RollingFileWriterBuilder::new(temp_dir.as_ref(), "test_file") .rotation(rotation) .filename_suffix("log") diff --git a/appenders/file/src/rotation.rs b/appenders/file/src/rotation.rs index f25be23c..24485f1e 100644 --- a/appenders/file/src/rotation.rs +++ b/appenders/file/src/rotation.rs @@ -15,8 +15,8 @@ use jiff::RoundMode; use jiff::ToSpan; use jiff::Unit; -use jiff::Zoned; -use jiff::ZonedRound; +use jiff::ZonedDateTime; +use jiff::ZonedDateTimeRound; /// Rotation policies for rolling files. #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -33,8 +33,8 @@ pub enum Rotation { impl Rotation { /// Get the next date timestamp based on the current date and rotation policy. - pub fn next_date_timestamp(&self, current_date: &Zoned) -> Option { - let round = ZonedRound::new().mode(RoundMode::Trunc); + pub fn next_date_timestamp(&self, current_date: &ZonedDateTime) -> Option { + let round = ZonedDateTimeRound::new().mode(RoundMode::Trunc); let next_date = match *self { Rotation::Never => return None, Rotation::Minutely => (current_date + 1.minute()).round(round.smallest(Unit::Minute)), @@ -62,13 +62,13 @@ mod tests { use std::str::FromStr; use jiff::Timestamp; - use jiff::Zoned; + use jiff::ZonedDateTime; use super::Rotation; #[test] fn test_next_date_timestamp() { - let current_date = Zoned::from_str("2024-08-10T17:12:52+08[+08]").unwrap(); + let current_date = ZonedDateTime::from_str("2024-08-10T17:12:52+08[+08]").unwrap(); assert_eq!(Rotation::Never.next_date_timestamp(¤t_date), None); From 49fddae71a2f663044dea34f2e2da56847d7bdda Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Mon, 23 Nov 2026 16:23:44 +0000 Subject: [PATCH 2/3] ci: switch retired macos-14 runner to macos-latest --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a7627a86..e9442a96 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,7 +67,7 @@ jobs: needs: msrv strategy: matrix: - os: [ ubuntu-24.04, macos-14, windows-2022 ] + os: [ ubuntu-24.04, macos-latest, windows-2022 ] rust-version: ${{ fromJson(needs.msrv.outputs.rust-versions) }} runs-on: ${{ matrix.os }} steps: From 5848ac44d3716f0b009cfb4f46e7104561af8ea0 Mon Sep 17 00:00:00 2001 From: tison Date: Tue, 24 Nov 2026 10:58:03 +0800 Subject: [PATCH 3/3] Apply suggestion from @tisonkun --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9442a96..875f1760 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,7 +67,7 @@ jobs: needs: msrv strategy: matrix: - os: [ ubuntu-24.04, macos-latest, windows-2022 ] + os: [ ubuntu-24.04, macos-15, windows-2022 ] rust-version: ${{ fromJson(needs.msrv.outputs.rust-versions) }} runs-on: ${{ matrix.os }} steps: