diff --git a/Cargo.lock b/Cargo.lock index 1c48899d..bc02f81f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -56,6 +56,7 @@ dependencies = [ "static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "terminfo 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "vte 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 10748987..a5385ba3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,6 +49,7 @@ image = "0.20.1" static_assertions = "0.2.5" terminfo = "0.6.1" url = "1.7.1" +time = "0.1.40" [target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os="dragonfly", target_os="openbsd"))'.dependencies] x11-dl = "2" diff --git a/src/lib.rs b/src/lib.rs index 1d393d1a..7ba3538b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -64,6 +64,7 @@ extern crate xdg; extern crate base64; extern crate terminfo; extern crate url; +extern crate time; #[macro_use] pub mod macros; diff --git a/src/logging.rs b/src/logging.rs index 71eaf822..bca8a7f0 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -19,6 +19,7 @@ //! log-level is sufficient for the level configured in `cli::Options`. use cli; use log::{self, Level}; +use time; use std::env; use std::fs::{File, OpenOptions}; @@ -121,12 +122,19 @@ impl log::Log for Logger { fn log(&self, record: &log::Record) { if self.enabled(record.metadata()) && record.target().starts_with("alacritty") { + let msg = format!( + "[{}] [{}] {}\n", + time::now().strftime("%F %R").unwrap(), + record.level(), + record.args() + ); + if let Ok(ref mut logfile) = self.logfile.lock() { - let _ = logfile.write_all(format!("{}\n", record.args()).as_ref()); + let _ = logfile.write_all(msg.as_ref()); } if let Ok(ref mut stdout) = self.stdout.lock() { - let _ = stdout.write_all(format!("{}\n", record.args()).as_ref()); + let _ = stdout.write_all(msg.as_ref()); } match record.level() {