[or-cvs] r15393: Make logging system somewhat more user grokable. (torbutton/trunk/src/components)

mikeperry at seul.org mikeperry at seul.org
Sat Jun 21 23:57:36 UTC 2008


Author: mikeperry
Date: 2008-06-21 19:57:36 -0400 (Sat, 21 Jun 2008)
New Revision: 15393

Modified:
   torbutton/trunk/src/components/torbutton-logger.js
Log:

Make logging system somewhat more user grokable.



Modified: torbutton/trunk/src/components/torbutton-logger.js
===================================================================
--- torbutton/trunk/src/components/torbutton-logger.js	2008-06-21 23:12:10 UTC (rev 15392)
+++ torbutton/trunk/src/components/torbutton-logger.js	2008-06-21 23:57:36 UTC (rev 15393)
@@ -52,6 +52,13 @@
 const nsIComponentRegistrar = Components.interfaces.nsIComponentRegistrar;
 const nsIObserverService = Components.interfaces.nsIObserverService;
 
+const logString = { 1:"VERB", 2:"DBUG", 3: "INFO", 4:"NOTE", 5:"WARN" };
+
+function padInt(i)
+{
+    return (i < 10) ? '0' + i : i;
+}
+
 TorbuttonLogger.prototype =
 {
   QueryInterface: function(iid)
@@ -82,41 +89,43 @@
   // method of nsIClassInfo
   getHelperForLanguage: function(count) { return null; },
 
+  formatLog: function(str, level) {
+      var d = new Date();
+      var now = padInt(d.getUTCMonth()+1)+"-"+padInt(d.getUTCDate())+" "+padInt(d.getUTCHours())+":"+padInt(d.getUTCMinutes())+":"+padInt(d.getUTCSeconds());
+      return "["+now+"] Torbutton("+logString[level]+"): "+str;
+  },
+
   // error console log
   eclog: function(level, str) {
-      var now = Date.now();
-      str = "["+now+"] ("+level+"): "+str;
       switch(this.logmethod) {
           case 0: // stderr
-              if(this.loglevel <= level) 
-                  dump(str+"\n");
+              if(this.loglevel <= level)
+                  dump(this.formatLog(str, level)+"\n");
               break;
           default: // errorconsole
               if(this.loglevel <= level)
-                  this._console.logStringMessage(str);
+                  this._console.logStringMessage(this.formatLog(str,level));
               break;
       }
   },
 
   log: function(level, str) {
-      var now = Date.now();
-      str = "["+now+"] ("+level+"): "+str;
       switch(this.logmethod) {
           case 2: // debuglogger
               if(this._debuglog) {
-                  this._debuglog.log((6-level), str);
+                  this._debuglog.log((6-level), this.formatLog(str,level));
                   break;
               }
               // fallthrough
           case 0: // stderr
               if(this.loglevel <= level) 
-                  dump(str+"\n");
+                  dump(this.formatLog(str,level)+"\n");
               break;
           default:
               dump("Bad log method: "+this.logmethod);
           case 1: // errorconsole
               if(this.loglevel <= level)
-                  this._console.logStringMessage(str);
+                  this._console.logStringMessage(this.formatLog(str,level));
               break;
       }
   },



More information about the tor-commits mailing list