Bug 708498 - Log milliseconds in TPS, code tidy; r=rnewman
authorGregory Szorc <gps@mozilla.com>
Fri, 09 Dec 2011 11:11:04 -0800
changeset 82377 6bc741986c80d66c3b2d558bc8b141cb78f759ef
parent 82376 cfd838426cf23333c56105e70314f14163e6ec27
child 82455 502049cfb331e7677454be8f2627c51f50708839
push id337
push usergszorc@mozilla.com
push dateFri, 09 Dec 2011 19:12:05 +0000
treeherderservices-central@6bc741986c80 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs708498
milestone11.0a1
Bug 708498 - Log milliseconds in TPS, code tidy; r=rnewman
services/sync/tps/extensions/tps/modules/logger.jsm
--- a/services/sync/tps/extensions/tps/modules/logger.jsm
+++ b/services/sync/tps/extensions/tps/modules/logger.jsm
@@ -123,24 +123,33 @@ var Logger =
   },
 
   log: function (msg, withoutPrefix) {
     dump(msg + "\n");
     if (withoutPrefix) {
       this.write(msg + "\n");
     }
     else {
-      var now = new Date()
-      this.write(now.getFullYear() + "-" + (now.getMonth() < 9 ? '0' : '') +
-          (now.getMonth() + 1) + "-" +
-          (now.getDate() < 10 ? '0' : '') + (now.getDate()) + " " +
-          (now.getHours() < 10 ? '0' : '') + now.getHours() + ":" +
-          (now.getMinutes() < 10 ? '0' : '') + now.getMinutes() + ":" +
-          (now.getSeconds() < 10 ? '0' : '') + now.getSeconds() + " " +
-          msg + "\n");
+      function pad(n, len) {
+        let s = "0000" + n;
+        return s.slice(-len);
+      }
+
+      let now = new Date();
+      let year    = pad(now.getFullYear(),     4);
+      let month   = pad(now.getMonth() + 1,    2);
+      let day     = pad(now.getDate(),         2);
+      let hour    = pad(now.getHours(),        2);
+      let minutes = pad(now.getMinutes(),      2);
+      let seconds = pad(now.getSeconds(),      2);
+      let ms      = pad(now.getMilliseconds(), 3);
+
+      this.write(year + "-" + month + "-" + day + " " +
+                 hour + ":" + minutes + ":" + seconds + "." + ms + " " +
+                 msg + "\n");
     }
   },
 
   clearPotentialError: function() {
     this._potentialError = null;
   },
 
   logPotentialError: function(msg) {