Skip to content

Commit 0e7979e

Browse files
authored
Merge branch 'main' into main
2 parents 5ada8ff + 3f4c621 commit 0e7979e

File tree

7 files changed

+100
-58
lines changed

7 files changed

+100
-58
lines changed

.github/workflows/coverage.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
USER: "test-user"
3131

3232
- name: Upload to codecov.io
33-
uses: codecov/codecov-action@v3
33+
uses: codecov/codecov-action@v5
3434
with:
35-
fail_ci_if_error: true
35+
token: ${{ secrets.CODECOV_TOKEN }}
36+
verbose: true # optional (default = false)

.github/workflows/lint.yml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ name: Lint Jobs
44
on:
55
push:
66
branches:
7-
- main
8-
- devel
7+
- main
8+
- devel
99
pull_request:
1010
branches:
11-
- main
12-
- devel
11+
- main
12+
- devel
1313

1414
jobs:
1515
rust-lint:
@@ -27,30 +27,30 @@ jobs:
2727
run: cargo check
2828

2929
- name: Run rustfmt
30-
run: cargo fmt -- --check
30+
run: cargo +nightly fmt -- --check
3131

3232
- name: Run Clippy
33-
run: cargo clippy --all-features
33+
run: rustup component add --toolchain 1.75-x86_64-unknown-linux-gnu clippy && cargo +1.75 clippy --all-features
3434
env:
3535
RUSTFLAGS: -D warnings
3636

3737
changelog-lint:
3838
name: Changelog Lint
3939
runs-on: ubuntu-latest
4040
steps:
41-
- name: Markdown Linting Action
42-
uses: avto-dev/markdown-lint@v1
43-
with:
44-
rules: /lint/rules/changelog.js
45-
config: --config /lint/config/changelog.yml
46-
args: 'CHANGELOG.md'
41+
- name: Markdown Linting Action
42+
uses: avto-dev/markdown-lint@v1
43+
with:
44+
rules: /lint/rules/changelog.js
45+
config: --config /lint/config/changelog.yml
46+
args: "CHANGELOG.md"
4747

4848
docs-lint:
4949
name: Docs Lint
5050
runs-on: ubuntu-latest
5151
steps:
52-
- name: Markdown Linting Action
53-
uses: avto-dev/markdown-lint@v1
54-
with:
55-
args: '**.md'
56-
ignore: 'CHANGELOG.md'
52+
- name: Markdown Linting Action
53+
uses: avto-dev/markdown-lint@v1
54+
with:
55+
args: "**.md"
56+
ignore: "CHANGELOG.md"

.github/workflows/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
runs-on: ${{ matrix.os }}
1818
strategy:
1919
matrix:
20-
rust_versions: ["stable", "1.69"]
20+
rust_versions: ["stable", "1.75"]
2121
os: [ubuntu-latest, windows-latest]
2222
steps:
2323
- name: Checkout the source code
@@ -36,7 +36,7 @@ jobs:
3636
# This test needs another run under the release mode
3737
cargo test --release --features simple_writer encode::pattern::tests::debug_release
3838
env:
39-
RUSTFLAGS: -D warnings
39+
RUSTFLAGS: -D warnings --cfg mock_time
4040

4141
features:
4242
name: Test Individual Features
@@ -55,15 +55,15 @@ jobs:
5555
run: |
5656
for feature in $(cargo read-manifest | jq -r '.features|keys|join("\n")'); do
5757
echo building with feature "$feature"
58-
RUSTFLAGS='-D warnings' cargo test --no-default-features --features "$feature"
58+
RUSTFLAGS='-D warnings --cfg mock_time' cargo test --no-default-features --features "$feature"
5959
done
6060
6161
bench:
6262
name: Benchmark the background_rotation feature
6363
runs-on: ubuntu-latest
6464
strategy:
6565
matrix:
66-
rust_versions: ["stable", "1.69"]
66+
rust_versions: ["stable", "1.75"]
6767
steps:
6868
- name: Checkout the source code
6969
uses: actions/checkout@v4

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Change Log
22

3+
## [Unreleased]
4+
5+
### Changed
6+
7+
* MSRV to 1.75
8+
* Update thread-id
9+
* Update thiserror
10+
* Update mock_instant
11+
* Update rand
12+
313
## [1.3.0]
414

515
### New

Cargo.toml

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
[package]
22
name = "log4rs"
33
version = "1.3.0"
4-
authors = ["Steven Fackler <sfackler@gmail.com>", "Evan Simmons <esims89@gmail.com>"]
4+
authors = [
5+
"Steven Fackler <sfackler@gmail.com>",
6+
"Evan Simmons <esims89@gmail.com>",
7+
]
58
description = "A highly configurable multi-output logging implementation for the `log` facade"
69
license = "MIT OR Apache-2.0"
710
repository = "https://github.com/estk/log4rs"
811
readme = "README.md"
912
keywords = ["log", "logger", "logging", "log4"]
1013
edition = "2018"
11-
rust-version = "1.69"
14+
rust-version = "1.75"
1215

1316
[features]
1417
default = ["all_components", "config_parsing", "yaml_format"]
15-
16-
config_parsing = ["humantime", "serde", "serde-value", "typemap-ors", "log/serde"]
18+
onstartup_trigger = []
19+
config_parsing = [
20+
"humantime",
21+
"serde",
22+
"serde-value",
23+
"typemap-ors",
24+
"log/serde",
25+
]
1726
yaml_format = ["serde_yaml"]
1827
json_format = ["serde_json"]
1928
toml_format = ["toml"]
20-
2129
console_appender = ["console_writer", "simple_writer", "pattern_encoder"]
2230
file_appender = ["parking_lot", "simple_writer", "pattern_encoder"]
2331
rolling_file_appender = ["parking_lot", "simple_writer", "pattern_encoder"]
@@ -26,8 +34,14 @@ delete_roller = []
2634
fixed_window_roller = []
2735
size_trigger = []
2836
time_trigger = ["rand"]
29-
onstartup_trigger = []
30-
json_encoder = ["serde", "serde_json", "chrono", "log-mdc", "log/serde", "thread-id"]
37+
json_encoder = [
38+
"serde",
39+
"serde_json",
40+
"chrono",
41+
"log-mdc",
42+
"log/serde",
43+
"thread-id",
44+
]
3145
pattern_encoder = ["chrono", "log-mdc", "thread-id"]
3246
ansi_writer = []
3347
console_writer = ["ansi_writer", "libc", "winapi"]
@@ -47,7 +61,7 @@ all_components = [
4761
"onstartup_trigger",
4862
"json_encoder",
4963
"pattern_encoder",
50-
"threshold_filter"
64+
"threshold_filter",
5165
]
5266

5367
gzip = ["flate2"]
@@ -58,28 +72,37 @@ harness = false
5872

5973
[dependencies]
6074
arc-swap = "1.6"
61-
chrono = { version = "0.4.23", optional = true, features = ["clock"], default-features = false }
75+
chrono = { version = "0.4.23", optional = true, features = [
76+
"clock",
77+
], default-features = false }
6278
flate2 = { version = "1.0", optional = true }
6379
fnv = "1.0"
6480
humantime = { version = "2.1", optional = true }
6581
log = { version = "0.4.20", features = ["std"] }
6682
log-mdc = { version = "0.1", optional = true }
6783
serde = { version = "1.0.196", optional = true, features = ["derive"] }
6884
serde-value = { version = "0.7", optional = true }
69-
thread-id = { version = "4", optional = true }
85+
thread-id = { version = "5", optional = true }
7086
typemap-ors = { version = "1.0.0", optional = true }
7187
serde_json = { version = "1.0", optional = true }
7288
serde_yaml = { version = "0.9", optional = true }
7389
toml = { version = "<0.8.10", optional = true }
7490
parking_lot = { version = "0.12.0", optional = true }
75-
rand = { version = "0.8", optional = true}
76-
thiserror = "1.0.15"
91+
rand = { version = "0.9", optional = true }
92+
thiserror = "2.0.12"
7793
anyhow = "1.0.28"
7894
derivative = "2.2"
7995
once_cell = "1.17.1"
96+
mock_instant = "0.5"
8097

8198
[target.'cfg(windows)'.dependencies]
82-
winapi = { version = "0.3", optional = true, features = ["handleapi", "minwindef", "processenv", "winbase", "wincon"] }
99+
winapi = { version = "0.3", optional = true, features = [
100+
"handleapi",
101+
"minwindef",
102+
"processenv",
103+
"winbase",
104+
"wincon",
105+
] }
83106

84107
[target.'cfg(not(windows))'.dependencies]
85108
libc = { version = "0.2", optional = true }
@@ -89,7 +112,6 @@ lazy_static = "1.4"
89112
streaming-stats = "0.2.3"
90113
humantime = "2.1"
91114
tempfile = "3.8"
92-
mock_instant = "0.3"
93115
serde_test = "1.0.176"
94116

95117
[[example]]
@@ -98,7 +120,11 @@ required-features = ["json_encoder", "console_appender"]
98120

99121
[[example]]
100122
name = "log_to_file"
101-
required-features = ["console_appender", "file_appender", "rolling_file_appender"]
123+
required-features = [
124+
"console_appender",
125+
"file_appender",
126+
"rolling_file_appender",
127+
]
102128

103129
[[example]]
104130
name = "compile_time_config"
@@ -111,3 +137,6 @@ required-features = ["file_appender", "rolling_file_appender", "size_trigger"]
111137
[[example]]
112138
name = "multi_logger_config"
113139
required-features = ["yaml_format", "config_parsing"]
140+
141+
[lints.rust]
142+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(mock_time)'] }

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![crates.io](https://img.shields.io/crates/v/log4rs.svg)](https://crates.io/crates/log4rs)
55
[![License: MIT OR Apache-2.0](https://img.shields.io/crates/l/clippy.svg)](#license)
66
![CI](https://github.com/estk/log4rs/workflows/CI/badge.svg)
7-
[![Minimum rustc version](https://img.shields.io/badge/rustc-1.69+-green.svg)](https://github.com/estk/log4rs#rust-version-requirements)
7+
[![Minimum rustc version](https://img.shields.io/badge/rustc-1.75+-green.svg)](https://github.com/estk/log4rs#rust-version-requirements)
88

99
log4rs is a highly configurable logging framework modeled after Java's Logback
1010
and log4j libraries.
@@ -54,7 +54,7 @@ fn main() {
5454

5555
## Rust Version Requirements
5656

57-
1.69
57+
1.75
5858

5959
## Building for Dev
6060

src/append/rolling_file/policy/compound/trigger/time.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
//!
33
//! Requires the `time_trigger` feature.
44
5-
#[cfg(test)]
6-
use chrono::NaiveDateTime;
75
use chrono::{DateTime, Datelike, Duration, Local, TimeZone, Timelike};
8-
#[cfg(test)]
9-
use mock_instant::{SystemTime, UNIX_EPOCH};
6+
107
use rand::Rng;
118
#[cfg(feature = "config_parsing")]
129
use serde::de;
@@ -176,22 +173,23 @@ impl TimeTrigger {
176173
/// Returns a new trigger which rolls the log once it has passed the
177174
/// specified time.
178175
pub fn new(config: TimeTriggerConfig) -> TimeTrigger {
179-
#[cfg(test)]
176+
#[cfg(mock_time)]
180177
let current = {
178+
use mock_instant::thread_local::{SystemTime, UNIX_EPOCH};
179+
181180
let now: std::time::Duration = SystemTime::now()
182181
.duration_since(UNIX_EPOCH)
183182
.expect("system time before Unix epoch");
184-
NaiveDateTime::from_timestamp_opt(now.as_secs() as i64, now.subsec_nanos())
185-
.unwrap()
186-
.and_local_timezone(Local)
183+
DateTime::from_timestamp(now.as_secs() as i64, now.subsec_nanos())
187184
.unwrap()
185+
.with_timezone(&Local)
188186
};
189187

190-
#[cfg(not(test))]
188+
#[cfg(not(mock_time))]
191189
let current = Local::now();
192190
let next_time = TimeTrigger::get_next_time(current, config.interval, config.modulate);
193191
let next_roll_time = if config.max_random_delay > 0 {
194-
let random_delay = rand::thread_rng().gen_range(0..config.max_random_delay);
192+
let random_delay = rand::rng().random_range(0..config.max_random_delay);
195193
next_time + Duration::seconds(random_delay as i64)
196194
} else {
197195
next_time
@@ -278,18 +276,19 @@ impl TimeTrigger {
278276

279277
impl Trigger for TimeTrigger {
280278
fn trigger(&self, _file: &LogFile) -> anyhow::Result<bool> {
281-
#[cfg(test)]
279+
#[cfg(mock_time)]
282280
let current = {
281+
use mock_instant::thread_local::{SystemTime, UNIX_EPOCH};
282+
283283
let now = SystemTime::now()
284284
.duration_since(UNIX_EPOCH)
285285
.expect("system time before Unix epoch");
286-
NaiveDateTime::from_timestamp_opt(now.as_secs() as i64, now.subsec_nanos())
287-
.unwrap()
288-
.and_local_timezone(Local)
286+
DateTime::from_timestamp(now.as_secs() as i64, now.subsec_nanos())
289287
.unwrap()
288+
.with_timezone(&Local)
290289
};
291290

292-
#[cfg(not(test))]
291+
#[cfg(not(mock_time))]
293292
let current: DateTime<Local> = Local::now();
294293
let mut next_roll_time = self.next_roll_time.write().unwrap();
295294
let is_trigger = current >= *next_roll_time;
@@ -340,7 +339,7 @@ impl Deserialize for TimeTriggerDeserializer {
340339
#[cfg(test)]
341340
mod test {
342341
use super::*;
343-
use mock_instant::MockClock;
342+
use mock_instant::thread_local::MockClock;
344343
use std::time::Duration;
345344

346345
fn trigger_with_time_and_modulate(
@@ -373,6 +372,7 @@ mod test {
373372
}
374373

375374
#[test]
375+
#[ignore]
376376
fn trigger() {
377377
let second_in_milli = 1000;
378378
let minute_in_milli = second_in_milli * 60;
@@ -392,7 +392,8 @@ mod test {
392392
(TimeTriggerInterval::Year(1), year_in_milli),
393393
];
394394
let modulate = false;
395-
for (time_trigger_interval, time_in_milli) in test_list.iter() {
395+
for (time_trigger_interval, time_in_milli) in &test_list {
396+
dbg!(time_in_milli);
396397
MockClock::set_system_time(Duration::from_millis(4 * day_in_milli)); // 1970/1/5 00:00:00 Monday
397398
assert_eq!(
398399
trigger_with_time_and_modulate(*time_trigger_interval, modulate, *time_in_milli),
@@ -418,7 +419,8 @@ mod test {
418419
(TimeTriggerInterval::Year(3), 3 * year_in_milli),
419420
];
420421
let modulate = true;
421-
for (time_trigger_interval, time_in_milli) in test_list.iter() {
422+
for (time_trigger_interval, time_in_milli) in &test_list {
423+
dbg!(time_in_milli);
422424
MockClock::set_system_time(Duration::from_millis(
423425
59 * day_in_milli + 2 * hour_in_milli + 2 * minute_in_milli + 2 * second_in_milli,
424426
)); // 1970/3/1 02:02:02 Sunday

0 commit comments

Comments
 (0)