]> git.lizzy.rs Git - rust.git/commitdiff
use format! compile time magics for indentation
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Wed, 1 Jun 2016 16:33:29 +0000 (18:33 +0200)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Wed, 1 Jun 2016 16:33:29 +0000 (18:33 +0200)
src/bin/miri.rs

index 33fb8393a7b427caa6169086b457dae59649519e..df1763ae530f95a3d8ab24835a399ec481285a85 100644 (file)
@@ -41,14 +41,19 @@ fn main() {
 
 #[miri_run]
 fn init_logger() {
+    const NSPACES: usize = 40;
     let format = |record: &log::LogRecord| {
         // prepend spaces to indent the final string
         let indentation = log_settings::settings().indentation;
-        let spaces = "                                        ";
-        let depth = indentation / spaces.len();
-        let indentation = indentation % spaces.len();
-        let indentation = &spaces[..indentation];
-        format!("{}:{}{:2}{} {}", record.level(), record.location().module_path(), depth, indentation, record.args())
+        let depth = indentation / NSPACES;
+        let indentation = indentation % NSPACES;
+        format!("{lvl}:{module}{depth:2}{indent:<indentation$}{text}",
+            lvl = record.level(),
+            module = record.location().module_path(),
+            depth = depth,
+            indentation = indentation,
+            indent = "",
+            text = record.args())
     };
 
     let mut builder = env_logger::LogBuilder::new();