deps: don't directly use time for logging (#2182)

Wanted to prune Cargo.toml a tiny bit and noticed I could just use humantime to do this instead of time for logging purposes. Of course I still pull it in via Cargo.lock though.
This commit is contained in:
Clement Tsang
2026-07-31 09:14:48 +00:00
committed by GitHub
parent c929b3de6a
commit 836ec5bf7f
5 changed files with 15 additions and 53 deletions
Generated
-1
View File
@@ -170,7 +170,6 @@ dependencies = [
"sysctl", "sysctl",
"sysinfo", "sysinfo",
"tempfile", "tempfile",
"time",
"timeless", "timeless",
"toml_edit", "toml_edit",
"unicode-ellipsis", "unicode-ellipsis",
+7 -24
View File
@@ -54,7 +54,7 @@ path = "src/bin/main.rs"
doc = false doc = false
[features] [features]
# Used for general builds. # Used for general release builds.
battery = ["dep:starship-battery"] battery = ["dep:starship-battery"]
nvidia = ["gpu", "dep:nvml-wrapper"] nvidia = ["gpu", "dep:nvml-wrapper"]
gpu = [] gpu = []
@@ -62,18 +62,13 @@ zfs = []
deploy = ["battery", "nvidia", "zfs"] deploy = ["battery", "nvidia", "zfs"]
default = ["deploy"] default = ["deploy"]
# Should not be included in builds. # These features should not be included in release builds.
logging = ["fern", "log", "time"] logging = ["fern", "log"]
generate_schema = ["schemars", "strum"] generate_schema = ["schemars", "strum"]
[dependencies] [dependencies]
anyhow = "1.0.101" anyhow = "1.0.101"
clap = { version = "4.6.4", features = [ clap = { version = "4.6.4", features = ["default", "cargo", "wrap_help", "derive"] }
"default",
"cargo",
"wrap_help",
"derive",
] }
concat-string = "1.0.1" concat-string = "1.0.1"
crossterm = "0.29.0" crossterm = "0.29.0"
ctrlc = { version = "3.5.2", features = ["termination"] } ctrlc = { version = "3.5.2", features = ["termination"] }
@@ -82,9 +77,7 @@ humantime = "2.3.0"
indexmap = "2.14.0" indexmap = "2.14.0"
indoc = "2.0.7" indoc = "2.0.7"
itertools = "0.15.0" itertools = "0.15.0"
nvml-wrapper = { version = "0.12.1", optional = true, features = [ nvml-wrapper = { version = "0.12.1", optional = true, features = ["legacy-functions"] }
"legacy-functions",
] }
ratatui = { version = "0.30.2", default-features = false, features = [ ratatui = { version = "0.30.2", default-features = false, features = [
"unstable-rendered-line-info", "unstable-rendered-line-info",
"layout-cache", "layout-cache",
@@ -102,14 +95,9 @@ unicode-ellipsis = "0.6.0"
unicode-segmentation = "1.13.3" unicode-segmentation = "1.13.3"
unicode-width = "0.2.2" unicode-width = "0.2.2"
# Used for logging. Mostly a debugging tool. # Used for logging. Mostly for dev-level debugging.
fern = { version = "0.7.1", optional = true } fern = { version = "0.7.1", optional = true }
log = { version = "0.4.29", optional = true } log = { version = "0.4.29", optional = true }
time = { version = "0.3.47", features = [
"local-offset",
"formatting",
"macros",
], optional = true }
# These are just used for JSON schema generation. # These are just used for JSON schema generation.
schemars = { version = "1.2.1", optional = true } schemars = { version = "1.2.1", optional = true }
@@ -150,12 +138,7 @@ tempfile = { version = "3.23.0", default-features = false }
portable-pty = "0.9.0" portable-pty = "0.9.0"
[build-dependencies] [build-dependencies]
clap = { version = "4.6.4", features = [ clap = { version = "4.6.4", features = ["default", "cargo", "wrap_help", "derive"] }
"default",
"cargo",
"wrap_help",
"derive",
] }
clap_complete = "4.6.7" clap_complete = "4.6.7"
clap_complete_nushell = "4.6.1" clap_complete_nushell = "4.6.1"
clap_complete_fig = "4.5.2" clap_complete_fig = "4.5.2"
+2 -1
View File
@@ -297,7 +297,8 @@ impl TimeSeriesData {
partition_point - 1 partition_point - 1
} else { } else {
// If the partition point was 0, then it means all values are too new to be // If the partition point was 0, then it means all values are too new to be
// pruned. crate::info!("Skipping prune."); // pruned.
// crate::info!("Skipping prune.");
return; return;
} }
}; };
-1
View File
@@ -293,7 +293,6 @@ fn create_collection_thread(
#[inline] #[inline]
pub fn start_bottom(enable_error_hook: &mut bool) -> anyhow::Result<()> { pub fn start_bottom(enable_error_hook: &mut bool) -> anyhow::Result<()> {
// let _profiler = dhat::Profiler::new_heap(); // let _profiler = dhat::Profiler::new_heap();
let args = args::get_args(); let args = args::get_args();
#[cfg(feature = "logging")] #[cfg(feature = "logging")]
+6 -26
View File
@@ -1,33 +1,12 @@
#[cfg(feature = "logging")]
use std::sync::OnceLock;
#[cfg(feature = "logging")]
pub static OFFSET: OnceLock<time::UtcOffset> = OnceLock::new();
#[cfg(feature = "logging")] #[cfg(feature = "logging")]
pub fn init_logger( pub fn init_logger(
min_level: log::LevelFilter, debug_file_name: Option<&std::ffi::OsStr>, min_level: log::LevelFilter, debug_file_name: Option<&std::ffi::OsStr>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let dispatch = fern::Dispatch::new() let dispatch = fern::Dispatch::new()
.format(|out, message, record| { .format(|out, message, record| {
let offset = OFFSET.get_or_init(|| {
time::UtcOffset::current_local_offset().unwrap_or(time::UtcOffset::UTC)
});
let offset_time = {
let utc = time::OffsetDateTime::now_utc();
utc.checked_to_offset(*offset).unwrap_or(utc)
};
out.finish(format_args!( out.finish(format_args!(
"{}[{}][{}] {}", "[{}][{}][{}] {}",
offset_time humantime::format_rfc3339_nanos(std::time::SystemTime::now()),
.format(&time::macros::format_description!(
// The weird "[[[" is because we need to escape a bracket ("[[") to show
// one "[". See https://time-rs.github.io/book/api/format-description.html
"[[[year]-[month]-[day]][[[hour]:[minute]:[second][subsecond digits:9]]"
))
.expect("log formatting shouldn't fail"),
record.target(), record.target(),
record.level(), record.level(),
message message
@@ -125,12 +104,13 @@ macro_rules! log_every_n_secs {
($level:expr, $n:expr, $($x:tt)*) => { ($level:expr, $n:expr, $($x:tt)*) => {
#[cfg(feature = "logging")] #[cfg(feature = "logging")]
{ {
static LAST_LOG: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0); use std::sync::atomic::{AtomicU64, Ordering};
let since_last_log = LAST_LOG.load(std::sync::atomic::Ordering::Relaxed); static LAST_LOG: AtomicU64 = AtomicU64::new(0);
let since_last_log = LAST_LOG.load(Ordering::Relaxed);
let now = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).expect("should be valid").as_secs(); let now = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).expect("should be valid").as_secs();
if now - since_last_log > $n { if now - since_last_log > $n {
LAST_LOG.store(now, std::sync::atomic::Ordering::Relaxed); LAST_LOG.store(now, Ordering::Relaxed);
log::log!($level, $($x)*); log::log!($level, $($x)*);
} }
} }