From d96d82736d50e1b72e9222c4e977fa838d91751f Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sat, 26 Jan 2019 10:56:11 +0100 Subject: [PATCH] use crate log and syslog --- Cargo.toml | 2 ++ src/api2/node/syslog.rs | 6 +++--- src/bin/proxmox-backup-api.rs | 8 ++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c72d0ef7..1a4d5599 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,8 @@ name = "proxmox_backup" path = "src/lib.rs" [dependencies] +log = "0.4" +syslog = "4.0" failure = "0.1" serde = "1.0" serde_json = "1.0" diff --git a/src/api2/node/syslog.rs b/src/api2/node/syslog.rs index 9fd5b5fe..cc385fa7 100644 --- a/src/api2/node/syslog.rs +++ b/src/api2/node/syslog.rs @@ -18,7 +18,7 @@ fn dump_journal( service: Option<&str>, ) -> Result<(u64, Vec), Error> { - let mut args = vec!["-o", "short", "--no-pagera"]; + let mut args = vec!["-o", "short", "--no-pager"]; if let Some(service) = service { args.extend(&["--unit", service]); } if let Some(since) = since { args.extend(&["--since", since]); } @@ -49,7 +49,7 @@ fn dump_journal( limit -= 1; } Err(err) => { - eprintln!("reading journal failed: {}", err); + log::error!("reading journal failed: {}", err); let _ = child.kill(); break; } @@ -59,7 +59,7 @@ fn dump_journal( let status = child.wait().unwrap(); if !status.success() { - eprintln!("journalctl failed with {}", status); + log::error!("journalctl failed with {}", status); } // HACK: ExtJS store.guaranteeRange() does not like empty array diff --git a/src/bin/proxmox-backup-api.rs b/src/bin/proxmox-backup-api.rs index 7a1cb543..6b1ebaed 100644 --- a/src/bin/proxmox-backup-api.rs +++ b/src/bin/proxmox-backup-api.rs @@ -17,6 +17,14 @@ use hyper; fn main() { + if let Err(err) = syslog::init( + syslog::Facility::LOG_DAEMON, + log::LevelFilter::Info, + Some("proxmox-backup-api")) { + eprintln!("unable to inititialize syslog: {}", err); + std::process::exit(-1); + } + let command : Arc = StringSchema::new("Command.") .format(Arc::new(ApiStringFormat::Enum(vec![ "start".into(),