Browse Source

Merge pull request #10 from bartelsielski/disable-chrono

Add 'chrono' compile time option
Sam Clements 5 years ago
parent
commit
67a89c82bb
2 changed files with 19 additions and 9 deletions
  1. 2 2
      Cargo.toml
  2. 17 7
      src/lib.rs

+ 2 - 2
Cargo.toml

@@ -7,11 +7,11 @@ description = "A logger that prints all messages with a readable output format"
 repository = "https://github.com/borntyping/rust-simple_logger"
 
 [features]
-default = ["colored"]
+default = ["colored", "chrono"]
 
 [dependencies]
 log = { version = "^0.4.5", features = ["std"] }
-chrono = "0.4.6"
+chrono = { version = "0.4.6", optional = true }
 colored = { version = "^1.6", optional = true }
 
 [target.'cfg(windows)'.dependencies]

+ 17 - 7
src/lib.rs

@@ -2,6 +2,7 @@
 
 #[cfg(windows)]
 extern crate atty;
+#[cfg(feature = "chrono")]
 extern crate chrono;
 #[cfg(feature = "colored")]
 extern crate colored;
@@ -9,6 +10,7 @@ extern crate log;
 #[cfg(windows)]
 extern crate winapi;
 
+#[cfg(feature = "chrono")]
 use chrono::Local;
 #[cfg(feature = "colored")]
 use colored::*;
@@ -46,13 +48,21 @@ impl Log for SimpleLogger {
             } else {
                 record.module_path().unwrap_or_default()
             };
-            println!(
-                "{} {:<5} [{}] {}",
-                Local::now().format("%Y-%m-%d %H:%M:%S,%3f"),
-                level_string,
-                target,
-                record.args()
-            );
+            #[cfg(feature = "chrono")] {
+                println!(
+                    "{} {:<5} [{}] {}",
+                    Local::now().format("%Y-%m-%d %H:%M:%S,%3f"),
+                    level_string,
+                    target,
+                    record.args());
+            }
+            #[cfg(not(feature = "chrono"))] {
+                println!(
+                    "{:<5} [{}] {}",
+                    level_string,
+                    target,
+                    record.args());
+            }
         }
     }