use crate log and syslog

This commit is contained in:
Dietmar Maurer 2019-01-26 10:56:11 +01:00
parent e182ab4a4a
commit d96d82736d
3 changed files with 13 additions and 3 deletions

View File

@ -9,6 +9,8 @@ name = "proxmox_backup"
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]
log = "0.4"
syslog = "4.0"
failure = "0.1" failure = "0.1"
serde = "1.0" serde = "1.0"
serde_json = "1.0" serde_json = "1.0"

View File

@ -18,7 +18,7 @@ fn dump_journal(
service: Option<&str>, service: Option<&str>,
) -> Result<(u64, Vec<Value>), Error> { ) -> Result<(u64, Vec<Value>), 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(service) = service { args.extend(&["--unit", service]); }
if let Some(since) = since { args.extend(&["--since", since]); } if let Some(since) = since { args.extend(&["--since", since]); }
@ -49,7 +49,7 @@ fn dump_journal(
limit -= 1; limit -= 1;
} }
Err(err) => { Err(err) => {
eprintln!("reading journal failed: {}", err); log::error!("reading journal failed: {}", err);
let _ = child.kill(); let _ = child.kill();
break; break;
} }
@ -59,7 +59,7 @@ fn dump_journal(
let status = child.wait().unwrap(); let status = child.wait().unwrap();
if !status.success() { if !status.success() {
eprintln!("journalctl failed with {}", status); log::error!("journalctl failed with {}", status);
} }
// HACK: ExtJS store.guaranteeRange() does not like empty array // HACK: ExtJS store.guaranteeRange() does not like empty array

View File

@ -17,6 +17,14 @@ use hyper;
fn main() { 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<Schema> = StringSchema::new("Command.") let command : Arc<Schema> = StringSchema::new("Command.")
.format(Arc::new(ApiStringFormat::Enum(vec![ .format(Arc::new(ApiStringFormat::Enum(vec![
"start".into(), "start".into(),