From 66a7baa67cd6f86c247978167dec0a88d0e2ae1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20B=C3=B6lz?= Date: Fri, 22 Sep 2023 17:03:41 +0200 Subject: [PATCH 1/3] Reopen log file on SIGHUP --- Cargo.lock | 14 ++++++++++++++ Cargo.toml | 3 ++- src/main.rs | 11 ++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ba38b971..934e3344 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -878,7 +878,9 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9f0c14694cbd524c8720dd69b0e3179344f04ebb5f90f2e4a440c6ea3b2f1ee" dependencies = [ + "libc", "log", + "reopen", "syslog", ] @@ -2348,6 +2350,17 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" +[[package]] +name = "reopen" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff42cec3acf85845f5b18b3cbb7fec619ccbd4a349f6ecbe1c62ab46d4d98293" +dependencies = [ + "autocfg", + "libc", + "signal-hook", +] + [[package]] name = "reqwest" version = "0.11.20" @@ -3480,6 +3493,7 @@ dependencies = [ "pico-args", "rand", "regex", + "reopen", "reqwest", "ring", "rmpv", diff --git a/Cargo.toml b/Cargo.toml index 309b379a..1659743b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,11 +37,12 @@ unstable = [] [target."cfg(not(windows))".dependencies] # Logging syslog = "6.1.0" +reopen = "1.0.3" [dependencies] # Logging log = "0.4.20" -fern = { version = "0.6.2", features = ["syslog-6"] } +fern = { version = "0.6.2", features = ["syslog-6", "reopen-1"] } tracing = { version = "0.1.37", features = ["log"] } # Needed to have lettre and webauthn-rs trace logging to work # A `dotenv` implementation for Rust diff --git a/src/main.rs b/src/main.rs index c200cf12..52e14593 100644 --- a/src/main.rs +++ b/src/main.rs @@ -326,7 +326,16 @@ fn init_logging(level: log::LevelFilter) -> Result<(), fern::InitError> { } if let Some(log_file) = CONFIG.log_file() { - logger = logger.chain(fern::log_file(log_file)?); + #[cfg(windows)] + { + logger = logger.chain(fern::log_file(log_file)?); + } + #[cfg(not(windows))] + { + const SIGHUP: i32 = 1; + let path = Path::new(&log_file); + logger = logger.chain(fern::log_reopen1(path, [SIGHUP])?); + } } #[cfg(not(windows))] From 193f86e43e4a68910727f2a8a464daecb2372faf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20B=C3=B6lz?= Date: Sat, 7 Oct 2023 18:35:03 +0200 Subject: [PATCH 2/3] reopen removed from Cargo.toml --- Cargo.lock | 1 - Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 934e3344..ddeabdd9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3493,7 +3493,6 @@ dependencies = [ "pico-args", "rand", "regex", - "reopen", "reqwest", "ring", "rmpv", diff --git a/Cargo.toml b/Cargo.toml index 1659743b..ee3e789c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,6 @@ unstable = [] [target."cfg(not(windows))".dependencies] # Logging syslog = "6.1.0" -reopen = "1.0.3" [dependencies] # Logging From b435ee49adfb93277584024129d22122683fce30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20B=C3=B6lz?= Date: Sat, 7 Oct 2023 18:54:11 +0200 Subject: [PATCH 3/3] tokio::signal::unix::SignalKind::hangup().as_raw_value() insted of 1 --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 52e14593..6c3593df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -332,7 +332,7 @@ fn init_logging(level: log::LevelFilter) -> Result<(), fern::InitError> { } #[cfg(not(windows))] { - const SIGHUP: i32 = 1; + const SIGHUP: i32 = tokio::signal::unix::SignalKind::hangup().as_raw_value(); let path = Path::new(&log_file); logger = logger.chain(fern::log_reopen1(path, [SIGHUP])?); }