Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Issue 5932: FBTrace scoped logging

  • Loading branch information...
commit 5144308c3bf2f300b081fdaa1bcc77578d6471dd 1 parent 6a04745
Jan Odvarko janodvarko authored
Showing with 47 additions and 2 deletions.
  1. +47 −2 extension/content/firebug/lib/trace.js
49 extension/content/firebug/lib/trace.js
View
@@ -10,6 +10,8 @@ const Cu = Components.utils;
// ********************************************************************************************* //
// Firebug Trace - FBTrace
+var TraceAPI = ["dump", "sysout", "setScope", "matchesNode", "time", "timeEnd"];
+
var scope = {};
try
@@ -22,7 +24,6 @@ catch (err)
{
getTracer: function(prefDomain)
{
- var TraceAPI = ["dump", "sysout", "setScope", "matchesNode", "time", "timeEnd"];
var TraceObj = {};
for (var i=0; i<TraceAPI.length; i++)
TraceObj[TraceAPI[i]] = function() {};
@@ -32,8 +33,52 @@ catch (err)
}
// ********************************************************************************************* //
+// Wrapper
+
+/**
+ * Wraps tracer for given option. Logs made throug the wrapper will automatially
Sebastian Zartner Owner

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

Jan Odvarko Owner

ah sorry,
Honza

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ * be checked against the option and only displayed if the option is true.
+ * If FBTrace console isn't installed all options are false and there is no
+ * additional performance penalty.
+ */
+function TraceWrapper(tracer, option)
+{
+ function createMethodWrapper(method)
+ {
+ return function()
+ {
+ // Check the option before the log is passed to the tracing console.
+ if (tracer[option])
+ tracer[method].apply(tracer, arguments);
+ }
+ }
+
+ for (var i=0; i<TraceAPI.length; i++)
+ {
+ var method = TraceAPI[i];
+ this[method] = createMethodWrapper(method);
+ }
+}
+
+// ********************************************************************************************* //
+
+var tracer = scope.traceConsoleService.getTracer("extensions.firebug");
+
+/**
+ * Support for scoped logging.
+ *
+ * Example:
+ * FBTrace = FBTrace.to("DBG_NET");
+ *
+ * // This log will be displayed only if DBG_NET option is on
+ * FBTrace.sysout("net.initialiaze");
+ */
+tracer.to = function(option)
+{
+ return new TraceWrapper(this, option);
+}
-return scope.traceConsoleService.getTracer("extensions.firebug");
+return tracer;
// ********************************************************************************************* //
});
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.