Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Issue 5932: FBTrace scoped logging

  • Loading branch information...
commit 5144308c3bf2f300b081fdaa1bcc77578d6471dd 1 parent 6a04745
Jan Odvarko authored September 21, 2012

Showing 1 changed file with 47 additions and 2 deletions. Show diff stats Hide diff stats

  1. 49  extension/content/firebug/lib/trace.js
49  extension/content/firebug/lib/trace.js
@@ -10,6 +10,8 @@ const Cu = Components.utils;
10 10
 // ********************************************************************************************* //
11 11
 // Firebug Trace - FBTrace
12 12
 
  13
+var TraceAPI = ["dump", "sysout", "setScope", "matchesNode", "time", "timeEnd"];
  14
+
13 15
 var scope = {};
14 16
 
15 17
 try
@@ -22,7 +24,6 @@ catch (err)
22 24
     {
23 25
         getTracer: function(prefDomain)
24 26
         {
25  
-            var TraceAPI = ["dump", "sysout", "setScope", "matchesNode", "time", "timeEnd"];
26 27
             var TraceObj = {};
27 28
             for (var i=0; i<TraceAPI.length; i++)
28 29
                 TraceObj[TraceAPI[i]] = function() {};
@@ -32,8 +33,52 @@ catch (err)
32 33
 }
33 34
 
34 35
 // ********************************************************************************************* //
  36
+// Wrapper
  37
+
  38
+/**
  39
+ * Wraps tracer for given option. Logs made throug the wrapper will automatially
  40
+ * be checked against the option and only displayed if the option is true.
  41
+ * If FBTrace console isn't installed all options are false and there is no
  42
+ * additional performance penalty.
  43
+ */
  44
+function TraceWrapper(tracer, option)
  45
+{
  46
+    function createMethodWrapper(method)
  47
+    {
  48
+        return function()
  49
+        {
  50
+            // Check the option before the log is passed to the tracing console.
  51
+            if (tracer[option])
  52
+                tracer[method].apply(tracer, arguments);
  53
+        }
  54
+    }
  55
+
  56
+    for (var i=0; i<TraceAPI.length; i++)
  57
+    {
  58
+        var method = TraceAPI[i];
  59
+        this[method] = createMethodWrapper(method);
  60
+    }
  61
+}
  62
+
  63
+// ********************************************************************************************* //
  64
+
  65
+var tracer = scope.traceConsoleService.getTracer("extensions.firebug");
  66
+
  67
+/**
  68
+ * Support for scoped logging.
  69
+ * 
  70
+ * Example:
  71
+ * FBTrace = FBTrace.to("DBG_NET");
  72
+ * 
  73
+ * // This log will be displayed only if DBG_NET option is on
  74
+ * FBTrace.sysout("net.initialiaze");
  75
+ */
  76
+tracer.to = function(option)
  77
+{
  78
+    return new TraceWrapper(this, option);
  79
+}
35 80
 
36  
-return scope.traceConsoleService.getTracer("extensions.firebug");
  81
+return tracer;
37 82
 
38 83
 // ********************************************************************************************* //
39 84
 });

0 notes on commit 5144308

Sebastian Zartner

Please reread your comments before committing. It should be 'through' and 'automatically'.
That's especially a problem for commit messages, which can't be changed easily as in Subversion.

Sebastian

Please sign in to comment.
Something went wrong with that request. Please try again.