Skip to content

Commit 8081d03

Browse files
authored
Merge branch 'main' into add-kv-support
2 parents 063346b + 771a6f1 commit 8081d03

File tree

9 files changed

+78
-55
lines changed

9 files changed

+78
-55
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: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ repository = "https://github.com/estk/log4rs"
1111
readme = "README.md"
1212
keywords = ["log", "logger", "logging", "log4"]
1313
edition = "2018"
14-
rust-version = "1.69"
14+
rust-version = "1.75"
1515

1616
[features]
1717
default = ["all_components", "config_parsing", "yaml_format"]
18-
18+
onstartup_trigger = []
1919
config_parsing = [
2020
"humantime",
2121
"serde",
@@ -26,7 +26,6 @@ config_parsing = [
2626
yaml_format = ["serde_yaml"]
2727
json_format = ["serde_json"]
2828
toml_format = ["toml"]
29-
3029
console_appender = ["console_writer", "simple_writer", "pattern_encoder"]
3130
file_appender = ["parking_lot", "simple_writer", "pattern_encoder"]
3231
rolling_file_appender = ["parking_lot", "simple_writer", "pattern_encoder"]
@@ -35,7 +34,6 @@ delete_roller = []
3534
fixed_window_roller = []
3635
size_trigger = []
3736
time_trigger = ["rand"]
38-
onstartup_trigger = []
3937
json_encoder = [
4038
"serde",
4139
"serde_json",
@@ -85,17 +83,18 @@ log = { version = "0.4.21", features = ["std"] }
8583
log-mdc = { version = "0.1", optional = true }
8684
serde = { version = "1.0.196", optional = true, features = ["derive"] }
8785
serde-value = { version = "0.7", optional = true }
88-
thread-id = { version = "4", optional = true }
86+
thread-id = { version = "5", optional = true }
8987
typemap-ors = { version = "1.0.0", optional = true }
9088
serde_json = { version = "1.0", optional = true }
9189
serde_yaml = { version = "0.9", optional = true }
9290
toml = { version = "<0.8.10", optional = true }
9391
parking_lot = { version = "0.12.0", optional = true }
94-
rand = { version = "0.8", optional = true }
95-
thiserror = "1.0.15"
92+
rand = { version = "0.9", optional = true }
93+
thiserror = "2.0.12"
9694
anyhow = "1.0.28"
9795
derivative = "2.2"
9896
once_cell = "1.17.1"
97+
mock_instant = "0.5"
9998

10099
[target.'cfg(windows)'.dependencies]
101100
winapi = { version = "0.3", optional = true, features = [
@@ -114,7 +113,6 @@ lazy_static = "1.4"
114113
streaming-stats = "0.2.3"
115114
humantime = "2.1"
116115
tempfile = "3.8"
117-
mock_instant = "0.3"
118116
serde_test = "1.0.176"
119117

120118
[[example]]
@@ -140,3 +138,6 @@ required-features = ["file_appender", "rolling_file_appender", "size_trigger"]
140138
[[example]]
141139
name = "multi_logger_config"
142140
required-features = ["yaml_format", "config_parsing"]
141+
142+
[lints.rust]
143+
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

src/config/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ pub use self::raw::{Deserializable, Deserialize, Deserializers, RawConfig};
2727
pub fn init_config(config: runtime::Config) -> Result<crate::Handle, SetLoggerError> {
2828
let logger = crate::Logger::new(config);
2929
log::set_max_level(logger.max_log_level());
30-
let handle = Handle {
31-
shared: logger.0.clone(),
32-
};
30+
let handle = logger.handle();
3331
log::set_boxed_logger(Box::new(logger)).map(|()| handle)
3432
}
3533

src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@
177177
//! For more examples see the [examples](https://github.com/estk/log4rs/tree/main/examples).
178178
//!
179179
180-
#![allow(where_clauses_object_safety, clippy::manual_non_exhaustive)]
180+
#![allow(clippy::manual_non_exhaustive)]
181181
#![warn(missing_docs)]
182182

183183
use std::{
@@ -414,6 +414,12 @@ impl Logger {
414414
pub fn max_log_level(&self) -> LevelFilter {
415415
self.0.load().root.max_log_level()
416416
}
417+
/// Get a `Handler` instance to reconfigure logger while running
418+
pub fn handle(&self) -> Handle {
419+
Handle {
420+
shared: self.0.clone(),
421+
}
422+
}
417423
}
418424

419425
impl log::Log for Logger {
@@ -462,6 +468,11 @@ impl Handle {
462468
log::set_max_level(shared.root.max_log_level());
463469
self.shared.store(Arc::new(shared));
464470
}
471+
472+
/// Get the maximum log level according to the current configuration
473+
pub fn max_log_level(&self) -> LevelFilter {
474+
self.shared.load().root.max_log_level()
475+
}
465476
}
466477

467478
#[cfg(test)]

0 commit comments

Comments
 (0)