Bug 1254073 - Log source file name and line number in cal.LOG; r=Fallen AURORA_BASE_20160307
authorGeoff Lankow <geoff@darktrojan.net>
Tue, 08 Mar 2016 00:08:45 +1300
changeset 24437 dde0501d2d9bedad7cdc014f37cc39287804def5
parent 24436 c408e8b9aa59c4ee9eb81cde95a443e7fa6eae59
child 24438 2b8c5494c89fa85925695a6a8347677e6b00c442
push id1623
push userclokep@gmail.com
push dateMon, 25 Apr 2016 14:53:28 +0000
treeherdercomm-beta@25267c20666e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFallen
bugs1254073
Bug 1254073 - Log source file name and line number in cal.LOG; r=Fallen
calendar/base/src/calUtils.js
--- a/calendar/base/src/calUtils.js
+++ b/calendar/base/src/calUtils.js
@@ -885,16 +885,25 @@ function setDefaultStartEndHour(aItem, a
         aItem.endDate = aItem.startDate.clone();
         aItem.endDate.minute += Preferences.get("calendar.event.defaultlength", 60);
     }
 }
 
 /****
  **** debug code
  ****/
+function _log(message, flag) {
+    let frame = Components.stack.caller.caller;
+    let filename = frame.filename ? frame.filename.split(" -> ").pop() : null;
+    let scriptError = Components.classes["@mozilla.org/scripterror;1"]
+                                .createInstance(Components.interfaces.nsIScriptError);
+    scriptError.init(message, filename, null, frame.lineNumber, frame.columnNumber,
+                     flag, "component javascript");
+    Services.console.logMessage(scriptError);
+}
 
 /**
  * Logs a string or an object to both stderr and the js-console only in the case
  * where the calendar.debug.log pref is set to true.
  *
  * @param aArg  either a string to log or an object whose entire set of
  *              properties should be logged.
  */
@@ -915,53 +924,38 @@ function LOG(aArg) {
         for (var prop in aArg) {
             string += prop + ': ' + aArg[prop] + '\n';
         }
         string += "End object\n";
     } else {
         string = aArg;
     }
 
-    // xxx todo consider using function debug()
     dump(string + '\n');
-    Services.console.logStringMessage(string);
+    _log(string, Components.interfaces.nsIScriptError.infoFlag);
 }
 
 /**
  * Dumps a warning to both console and js console.
  *
  * @param aMessage warning message
  */
 function WARN(aMessage) {
     dump("Warning: " + aMessage + '\n');
-    let frame = Components.stack.caller;
-    let filename = frame.filename ? frame.filename.split(" -> ").pop() : null;
-    let scriptError = Components.classes["@mozilla.org/scripterror;1"]
-                                .createInstance(Components.interfaces.nsIScriptError);
-    scriptError.init(aMessage, filename, null, frame.lineNumber, frame.columnNumber,
-                     Components.interfaces.nsIScriptError.warningFlag,
-                     "component javascript");
-    Services.console.logMessage(scriptError);
+    _log(aMessage, Components.interfaces.nsIScriptError.warningFlag);
 }
 
 /**
  * Dumps an error to both console and js console.
  *
  * @param aMessage error message
  */
 function ERROR(aMessage) {
     dump("Error: " + aMessage + '\n');
-    let frame = Components.stack.caller;
-    let filename = frame.filename ? frame.filename.split(" -> ").pop() : null;
-    let scriptError = Components.classes["@mozilla.org/scripterror;1"]
-                                .createInstance(Components.interfaces.nsIScriptError);
-    scriptError.init(aMessage, filename, null, frame.lineNumber, frame.columnNumber,
-                     Components.interfaces.nsIScriptError.errorFlag,
-                     "component javascript");
-    Services.console.logMessage(scriptError);
+    _log(aMessage, Components.interfaces.nsIScriptError.errorFlag);
 }
 
 /**
  * Returns a string describing the current js-stack with filename and line
  * numbers.
  *
  * @param aDepth (optional) The number of frames to include. Defaults to 5.
  * @param aSkip  (optional) Number of frames to skip