Skip to content

Commit

Permalink
Merge pull request #3909 from tobiasmboelz/reopen-log-file
Browse files Browse the repository at this point in the history
Reopen log file on SIGHUP
  • Loading branch information
dani-garcia authored Oct 21, 2023
2 parents ff8db4f + b435ee4 commit 18fbc1c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ syslog = "6.1.0"
[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
Expand Down
11 changes: 10 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = tokio::signal::unix::SignalKind::hangup().as_raw_value();
let path = Path::new(&log_file);
logger = logger.chain(fern::log_reopen1(path, [SIGHUP])?);
}
}

#[cfg(not(windows))]
Expand Down

0 comments on commit 18fbc1c

Please sign in to comment.