aboutsummaryrefslogtreecommitdiff
path: root/src/garage
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2024-03-26 16:34:40 +0100
committerAlex Auvolat <alex@adnab.me>2024-03-26 16:34:40 +0100
commitf7cd4eb60093910fe23745fce69db49fce591c32 (patch)
tree9d219453954f7616874d7bfa76e93fa843dfaa4e /src/garage
parentcdde0f19ee37848370d4a138d95c55bfaca820ed (diff)
parent95eb8808e8ede5439cf6352ce4f9a148fac2f236 (diff)
downloadgarage-f7cd4eb60093910fe23745fce69db49fce591c32.tar.gz
garage-f7cd4eb60093910fe23745fce69db49fce591c32.zip
Merge branch 'main' into next-0.10
Diffstat (limited to 'src/garage')
-rw-r--r--src/garage/Cargo.toml3
-rw-r--r--src/garage/main.rs65
-rw-r--r--src/garage/tests/k2v/poll.rs2
3 files changed, 59 insertions, 11 deletions
diff --git a/src/garage/Cargo.toml b/src/garage/Cargo.toml
index 17da68f8..a4acbb1f 100644
--- a/src/garage/Cargo.toml
+++ b/src/garage/Cargo.toml
@@ -59,6 +59,7 @@ opentelemetry.workspace = true
opentelemetry-prometheus = { workspace = true, optional = true }
opentelemetry-otlp = { workspace = true, optional = true }
prometheus = { workspace = true, optional = true }
+syslog-tracing = { workspace = true, optional = true }
[dev-dependencies]
aws-config.workspace = true
@@ -97,6 +98,8 @@ kubernetes-discovery = [ "garage_rpc/kubernetes-discovery" ]
metrics = [ "garage_api/metrics", "opentelemetry-prometheus", "prometheus" ]
# Exporter for the OpenTelemetry Collector.
telemetry-otlp = [ "opentelemetry-otlp" ]
+# Logging to syslog
+syslog = [ "syslog-tracing" ]
# NOTE: bundled-libs and system-libs should be treat as mutually exclusive;
# exactly one of them should be enabled.
diff --git a/src/garage/main.rs b/src/garage/main.rs
index 5e9c061f..92fd4d0c 100644
--- a/src/garage/main.rs
+++ b/src/garage/main.rs
@@ -138,17 +138,8 @@ async fn main() {
let opt = Opt::from_clap(&Opt::clap().version(version.as_str()).get_matches());
// Initialize logging as well as other libraries used in Garage
- if std::env::var("RUST_LOG").is_err() {
- let default_log = match &opt.cmd {
- Command::Server => "netapp=info,garage=info",
- _ => "netapp=warn,garage=warn",
- };
- std::env::set_var("RUST_LOG", default_log)
- }
- tracing_subscriber::fmt()
- .with_writer(std::io::stderr)
- .with_env_filter(tracing_subscriber::filter::EnvFilter::from_default_env())
- .init();
+ init_logging(&opt);
+
sodiumoxide::init().expect("Unable to init sodiumoxide");
let res = match opt.cmd {
@@ -171,6 +162,58 @@ async fn main() {
}
}
+fn init_logging(opt: &Opt) {
+ if std::env::var("RUST_LOG").is_err() {
+ let default_log = match &opt.cmd {
+ Command::Server => "netapp=info,garage=info",
+ _ => "netapp=warn,garage=warn",
+ };
+ std::env::set_var("RUST_LOG", default_log)
+ }
+
+ let env_filter = tracing_subscriber::filter::EnvFilter::from_default_env();
+
+ if std::env::var("GARAGE_LOG_TO_SYSLOG")
+ .map(|x| x == "1" || x == "true")
+ .unwrap_or(false)
+ {
+ #[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()
+ .with_writer(std::io::stderr)
+ .with_env_filter(env_filter)
+ .init();
+}
+
async fn cli_command(opt: Opt) -> Result<(), Error> {
let config = if (opt.secrets.rpc_secret.is_none() && opt.secrets.rpc_secret_file.is_none())
|| opt.rpc_host.is_none()
diff --git a/src/garage/tests/k2v/poll.rs b/src/garage/tests/k2v/poll.rs
index 277f8bc8..7c06cea9 100644
--- a/src/garage/tests/k2v/poll.rs
+++ b/src/garage/tests/k2v/poll.rs
@@ -10,6 +10,7 @@ use crate::common;
use crate::json_body;
#[tokio::test]
+#[ignore = "currently broken"]
async fn test_poll_item() {
let ctx = common::context();
let bucket = ctx.create_bucket("test-k2v-poll-item");
@@ -98,6 +99,7 @@ async fn test_poll_item() {
}
#[tokio::test]
+#[ignore = "currently broken"]
async fn test_poll_range() {
let ctx = common::context();
let bucket = ctx.create_bucket("test-k2v-poll-range");