1 /* See license.txt for terms of usage */
  2 
  3 define([], function() {
  4 
  5 // ********************************************************************************************* //
  6 // Constants
  7 
  8 const Cu = Components.utils;
  9 
 10 var scope = {};
 11 Cu["import"]("resource://firebug/fbtrace.js", scope);
 12 
 13 // ********************************************************************************************* //
 14 // Wrapper
 15 
 16 /**
 17  * Wraps tracer for given option. Logs made through the wrapper will automatically
 18  * be checked against the option and only displayed if the option is true.
 19  * If FBTrace console isn't installed all options are false and there is no
 20  * additional performance penalty.
 21  */
 22 function TraceWrapper(tracer, option)
 23 {
 24     function createMethodWrapper(method)
 25     {
 26         return function()
 27         {
 28             // Check the option before the log is passed to the tracing console.
 29             if (tracer[option])
 30                 tracer[method].apply(tracer, arguments);
 31         }
 32     }
 33 
 34     for (var i=0; i<TraceAPI.length; i++)
 35     {
 36         var method = TraceAPI[i];
 37         this[method] = createMethodWrapper(method);
 38     }
 39 }
 40 
 41 // ********************************************************************************************* //
 42 
 43 var tracer = scope.FBTrace;
 44 
 45 /**
 46  * Support for scoped logging.
 47  * 
 48  * Example:
 49  * FBTrace = FBTrace.to("DBG_NET");
 50  * 
 51  * // This log will be displayed only if DBG_NET option is on
 52  * FBTrace.sysout("net.initialiaze");
 53  */
 54 tracer.to = function(option)
 55 {
 56     return new TraceWrapper(this, option);
 57 }
 58 
 59 return tracer;
 60 
 61 // ********************************************************************************************* //
 62 });
 63