aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2024-03-20 14:36:13 +0100
committerAlex Auvolat <alex@adnab.me>2024-03-20 14:39:04 +0100
commit84018be8622b582ad8853df042d10f0e122e6316 (patch)
treefed2a61dd3e89bbbd3a80cd9b97d14b66eba1efd
parent091e6936706ee8bfe34021e601ad984866c209d8 (diff)
downloadgarage-84018be8622b582ad8853df042d10f0e122e6316.tar.gz
garage-84018be8622b582ad8853df042d10f0e122e6316.zip
[syslog] warning when syslog support is not enabled
-rw-r--r--src/garage/main.rs51
1 files changed, 29 insertions, 22 deletions
diff --git a/src/garage/main.rs b/src/garage/main.rs
index 3fe96338..2f9ae508 100644
--- a/src/garage/main.rs
+++ b/src/garage/main.rs
@@ -175,32 +175,39 @@ fn init_logging(opt: &Opt) {
let env_filter = tracing_subscriber::filter::EnvFilter::from_default_env();
- #[cfg(feature = "syslog")]
if std::env::var("GARAGE_LOG_TO_SYSLOG")
.map(|x| x == "1" || x == "true")
.unwrap_or(false)
{
- use std::ffi::CStr;
- use syslog_tracing::{Facility, Options, Syslog};
-
- let syslog = Syslog::new(
- CStr::from_bytes_with_nul(b"garage\0").unwrap(),
- Options::LOG_PID | Options::LOG_PERROR,
- Facility::Daemon,
- )
- .expect("Unable to init syslog");
-
- tracing_subscriber::fmt()
- .with_writer(syslog)
- .with_env_filter(env_filter)
- .with_ansi(false) // disable ANSI escape sequences (colours)
- .with_file(false)
- .with_level(false)
- .without_time()
- .compact()
- .init();
-
- return;
+ #[cfg(feature = "syslog")]
+ {
+ use std::ffi::CStr;
+ use syslog_tracing::{Facility, Options, Syslog};
+
+ let syslog = Syslog::new(
+ CStr::from_bytes_with_nul(b"garage\0").unwrap(),
+ Options::LOG_PID | Options::LOG_PERROR,
+ Facility::Daemon,
+ )
+ .expect("Unable to init syslog");
+
+ tracing_subscriber::fmt()
+ .with_writer(syslog)
+ .with_env_filter(env_filter)
+ .with_ansi(false) // disable ANSI escape sequences (colours)
+ .with_file(false)
+ .with_level(false)
+ .without_time()
+ .compact()
+ .init();
+
+ return;
+ }
+ #[cfg(not(feature = "syslog"))]
+ {
+ eprintln!("Syslog support is not enabled in this build.");
+ std::process::exit(1);
+ }
}
tracing_subscriber::fmt()