-use failure::*;
-use chrono::{TimeZone, Local};
+use anyhow::{Error};
use std::io::Write;
/// Log messages with timestamps into files
///
-/// Logs messages to file, and optionaly to standart output.
+/// Logs messages to file, and optionally to standard output.
///
///
/// #### Example:
/// ```
/// #[macro_use] extern crate proxmox_backup;
-/// # use failure::*;
+/// # use anyhow::{bail, format_err, Error};
/// use proxmox_backup::tools::FileLogger;
///
/// # std::fs::remove_file("test.log");
let mut stdout = std::io::stdout();
if self.to_stdout {
- stdout.write(msg.as_bytes()).unwrap();
- stdout.write(b"\n").unwrap();
+ stdout.write_all(msg.as_bytes()).unwrap();
+ stdout.write_all(b"\n").unwrap();
}
- let line = format!("{}: {}\n", Local.timestamp(Local::now().timestamp(), 0).to_rfc3339(), msg);
- self.file.write(line.as_bytes()).unwrap();
+ let now = proxmox::tools::time::epoch_i64();
+ let rfc3339 = proxmox::tools::time::epoch_to_rfc3339(now).unwrap();
+
+ let line = format!("{}: {}\n", rfc3339, msg);
+ self.file.write_all(line.as_bytes()).unwrap();
}
}