Skip to content

Commit 425c853

Browse files
committed
switch from chrono to jiff (#96)
1 parent 3720f50 commit 425c853

5 files changed

Lines changed: 20 additions & 15 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ keywords = ["tui", "log", "logger", "widget", "dispatcher"]
1212

1313
[dependencies]
1414
log = "0.4"
15-
chrono = { version = "^0.4.38", default-features = false, features = ["clock"] }
15+
jiff = "0.2"
1616
ratatui = { version = "0.30", default-features = false}
1717
tracing = {version = "0.1.40", optional = true}
1818
tracing-subscriber = {version = "0.3", optional = true}

src/logger/inner.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::logger::fast_hash::fast_str_hash;
22
use crate::{CircularBuffer, LevelConfig, TuiLoggerFile};
3-
use chrono::{DateTime, Local};
43
use env_filter::Filter;
4+
use jiff::Zoned;
55
use log::{Level, LevelFilter, Log, Metadata, Record};
66
use parking_lot::Mutex;
77
use std::collections::HashMap;
@@ -41,7 +41,7 @@ impl StringOrStatic {
4141
}
4242

4343
pub struct ExtLogRecord {
44-
pub timestamp: DateTime<Local>,
44+
pub timestamp: Zoned,
4545
pub level: Level,
4646
target: String,
4747
file: Option<StringOrStatic>,
@@ -84,7 +84,7 @@ impl ExtLogRecord {
8484
.map(|s| StringOrStatic::IsString(s.to_string()))
8585
});
8686
ExtLogRecord {
87-
timestamp: chrono::Local::now(),
87+
timestamp: Zoned::now(),
8888
level: record.level(),
8989
target: record.target().to_string(),
9090
file,
@@ -93,7 +93,7 @@ impl ExtLogRecord {
9393
msg: format!("{}", record.args()),
9494
}
9595
}
96-
fn overrun(timestamp: DateTime<Local>, total: usize, elements: usize) -> Self {
96+
fn overrun(timestamp: Zoned, total: usize, elements: usize) -> Self {
9797
ExtLogRecord {
9898
timestamp,
9999
level: Level::Warn,
@@ -148,8 +148,11 @@ impl TuiLogger {
148148
}
149149
if total > elements {
150150
// Too many events received, so some have been lost
151-
let new_log_entry =
152-
ExtLogRecord::overrun(reversed[reversed.len() - 1].timestamp, total, elements);
151+
let new_log_entry = ExtLogRecord::overrun(
152+
reversed[reversed.len() - 1].timestamp.clone(),
153+
total,
154+
elements,
155+
);
153156
reversed.push(new_log_entry);
154157
}
155158
while let Some(log_entry) = reversed.pop() {
@@ -198,7 +201,7 @@ impl TuiLogger {
198201
log::Level::Trace => ("TRACE", "T", true),
199202
};
200203
if let Some(fmt) = file_options.timestamp_fmt.as_ref() {
201-
output.push_str(&format!("{}", log_entry.timestamp.format(fmt)));
204+
output.push_str(&log_entry.timestamp.strftime(fmt).to_string());
202205
output.push(file_options.format_separator);
203206
}
204207
match file_options.format_output_level {
@@ -294,8 +297,10 @@ impl TuiLogger {
294297
let log_entry = ExtLogRecord::from(record);
295298
let mut events_lock = self.hot_log.lock();
296299
events_lock.events.push(log_entry);
297-
let need_signal =
298-
events_lock.events.total_elements().is_multiple_of(events_lock.events.capacity() / 2);
300+
let need_signal = events_lock
301+
.events
302+
.total_elements()
303+
.is_multiple_of(events_lock.events.capacity() / 2);
299304
if need_signal {
300305
if let Some(jh) = events_lock.mover_thread.as_ref() {
301306
thread::Thread::unpark(jh.thread());

src/widget/smart.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<'a> TuiLoggerSmartWidget<'a> {
130130
self
131131
}
132132
/// The format string can be defined as described in
133-
/// <https://docs.rs/chrono/0.4.19/chrono/format/strftime/index.html>
133+
/// <https://docs.rs/jiff/latest/jiff/fmt/strtime/index.html>
134134
///
135135
/// If called with None, timestamp is not included in output.
136136
///
@@ -199,12 +199,12 @@ impl<'a> Widget for TuiLoggerSmartWidget<'a> {
199199
.events
200200
.iter()
201201
.next()
202-
.map(|entry| entry.timestamp.timestamp_millis());
202+
.map(|entry| entry.timestamp.timestamp().as_millisecond());
203203
let last_timestamp = tui_lock
204204
.events
205205
.rev_iter()
206206
.next()
207-
.map(|entry| entry.timestamp.timestamp_millis());
207+
.map(|entry| entry.timestamp.timestamp().as_millisecond());
208208
if let Some(first) = first_timestamp {
209209
if let Some(last) = last_timestamp {
210210
let dt = last - first;

src/widget/standard.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl<'b> TuiLoggerWidget<'b> {
148148
self
149149
}
150150
/// The format string can be defined as described in
151-
/// <https://docs.rs/chrono/0.4.19/chrono/format/strftime/index.html>
151+
/// <https://docs.rs/jiff/latest/jiff/fmt/strtime/index.html>
152152
///
153153
/// If called with None, timestamp is not included in output.
154154
///

src/widget/standard_formatter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl LogFormatter for LogStandardFormatter {
8282
};
8383
let col_style = col_style.unwrap_or(self.style);
8484
if let Some(fmt) = self.format_timestamp.as_ref() {
85-
output.push_str(&format!("{}", evt.timestamp.format(fmt)));
85+
output.push_str(&evt.timestamp.strftime(fmt).to_string());
8686
output.push(self.format_separator);
8787
}
8888
match &self.format_output_level {

0 commit comments

Comments
 (0)