fix: Use localtime for log output

This commit is contained in:
Arne Beer 2022-11-14 13:56:25 +01:00
parent 57da8ff3a7
commit 4c27640484
No known key found for this signature in database
GPG key ID: CC9408F679023B65
5 changed files with 31 additions and 5 deletions

View file

@ -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

1
Cargo.lock generated
View file

@ -1556,6 +1556,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48dfff04aade74dd495b007c831cd6f4e0cee19c344dd9dc0884c0289b70a786"
dependencies = [
"log",
"termcolor",
"time 0.3.13",
]

View file

@ -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 }

View file

@ -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) =

View file

@ -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
}