Repository: pkolaczk/fclones (language: rust)

Issue:
Add timestamps to the diagnostic log
Example:
```
[2020-06-23 18:25:13.126] fclones: info: Found 963 (3.0 MB) duplicate files
```


Discussion / hints:

Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index e195115..29dbea2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,6 +13,7 @@ readme = "README.md"
 atomic-counter = "1.0.1"
 bytesize = "1.0.0"
 byte-unit = "3.1.3"
+chrono = "0.4.11"
 clap = "2.33.0"
 console = "0.11.2"
 csv = "1.1.3"
diff --git a/src/log.rs b/src/log.rs
index db6b1d1..3ed105a 100644
--- a/src/log.rs
+++ b/src/log.rs
@@ -5,6 +5,7 @@ use indicatif::ProgressDrawTarget;
 use nom::lib::std::fmt::Display;
 
 use crate::progress::FastProgressBar;
+use chrono::Local;
 
 pub struct Log {
     program_name: String,
@@ -89,10 +90,16 @@ impl Log {
         }
     }
 
+    const TIMESTAMP_FMT: &'static str = "[%Y-%m-%d %H:%M:%S.%3f]";
+
     pub fn info<I: Display>(&self, msg: I) {
+        let timestamp = Local::now();
         let msg = format!(
-            "{}: {} {}",
-            self.program_name,
+            "{} {}: {} {}",
+            style(timestamp.format(Self::TIMESTAMP_FMT))
+                .for_stderr()
+                .green(),
+            style(&self.program_name).for_stderr().yellow(),
             style(" info:").for_stderr().green(),
             msg
         );
@@ -100,9 +107,13 @@ impl Log {
     }
 
     pub fn warn<I: Display>(&self, msg: I) {
+        let timestamp = Local::now();
         let msg = format!(
-            "{}: {} {}",
-            self.program_name,
+            "{} {}: {} {}",
+            style(timestamp.format(Self::TIMESTAMP_FMT))
+                .for_stderr()
+                .green(),
+            style(&self.program_name).for_stderr().yellow(),
             style(" warn:").for_stderr().yellow(),
             msg
         );
@@ -110,9 +121,13 @@ impl Log {
     }
 
     pub fn err<I: Display>(&self, msg: I) {
+        let timestamp = Local::now();
         let msg = format!(
-            "{}: {} {}",
-            self.program_name,
+            "{} {}: {} {}",
+            style(timestamp.format(Self::TIMESTAMP_FMT))
+                .for_stderr()
+                .green(),
+            style(&self.program_name).for_stderr().yellow(),
             style("error:").for_stderr().red(),
             msg
         );


Test patch: