From 4c27640484e075b59f3ad327d294c26cdab91632 Mon Sep 17 00:00:00 2001 From: Arne Beer Date: Mon, 14 Nov 2022 13:56:25 +0100 Subject: [PATCH] fix: Use localtime for log output --- CHANGELOG.md | 1 + Cargo.lock | 1 + Cargo.toml | 2 +- client/main.rs | 16 ++++++++++++++-- daemon/main.rs | 16 ++++++++++++++-- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdb94b3..0e5303c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), This gives users more control over how their editor should be started. - Don't show the version warning message between daemon and client, when using any `--json` flag. - Fix some test failures in non-standard environments for NixOS test suite ([#346](https://github.com/Nukesor/pueue/issues/346)). +- The time in pueue's logs will now be in localtime instead of UTC [#385](https://github.com/Nukesor/pueue/issues/385). ### Misc diff --git a/Cargo.lock b/Cargo.lock index a2eb7bf..c764a4e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1556,6 +1556,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48dfff04aade74dd495b007c831cd6f4e0cee19c344dd9dc0884c0289b70a786" dependencies = [ "log", + "termcolor", "time 0.3.13", ] diff --git a/Cargo.toml b/Cargo.toml index f737466..77a18ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,7 +70,7 @@ handlebars = "4" pest = "2" pest_derive = "2" shell-escape = "0.1" -simplelog = { version = "0.12", default-features = false } +simplelog = "0.12" tempfile = "3" chrono = { workspace = true } diff --git a/client/main.rs b/client/main.rs index c99a7db..57853cb 100644 --- a/client/main.rs +++ b/client/main.rs @@ -3,7 +3,8 @@ use std::path::PathBuf; use anyhow::{bail, Context, Result}; use clap::{IntoApp, Parser}; use clap_complete::{generate_to, shells}; -use simplelog::{Config, LevelFilter, SimpleLogger}; +use log::warn; +use simplelog::{Config, ConfigBuilder, LevelFilter, SimpleLogger}; use pueue_lib::settings::Settings; @@ -45,7 +46,18 @@ async fn main() -> Result<()> { 2 => LevelFilter::Info, _ => LevelFilter::Debug, }; - SimpleLogger::init(level, Config::default()).unwrap(); + + // Try to initialize the logger with the timezone set to the Local time of the machine. + let mut builder = ConfigBuilder::new(); + let logger_config = match builder.set_time_offset_to_local() { + Err(_) => { + warn!("Failed to determine the local time of this machine. Fallback to UTC."); + Config::default() + } + Ok(builder) => builder.build(), + }; + + SimpleLogger::init(level, logger_config).unwrap(); // Try to read settings from the configuration file. let (mut settings, config_found) = diff --git a/daemon/main.rs b/daemon/main.rs index 3c6f5f4..94c9378 100644 --- a/daemon/main.rs +++ b/daemon/main.rs @@ -2,7 +2,8 @@ use std::process::Command; use anyhow::Result; use clap::Parser; -use simplelog::{Config, LevelFilter, SimpleLogger}; +use log::warn; +use simplelog::{Config, ConfigBuilder, LevelFilter, SimpleLogger}; use pueue_daemon_lib::cli::CliArguments; use pueue_daemon_lib::run; @@ -23,7 +24,18 @@ async fn main() -> Result<()> { 2 => LevelFilter::Info, _ => LevelFilter::Debug, }; - SimpleLogger::init(level, Config::default()).unwrap(); + + // Try to initialize the logger with the timezone set to the Local time of the machine. + let mut builder = ConfigBuilder::new(); + let logger_config = match builder.set_time_offset_to_local() { + Err(_) => { + warn!("Failed to determine the local time of this machine. Fallback to UTC."); + Config::default() + } + Ok(builder) => builder.build(), + }; + + SimpleLogger::init(level, logger_config).unwrap(); run(opt.config, opt.profile, false).await }