This is just some static backup of the original site, don't expect every link to work!

Changeset 509348 for modules/vI_log.js


Ignore:
Timestamp:
Nov 3, 2014, 12:35:40 PM (8 years ago)
Author:
rene <rene@…>
Branches:
ng_0.9
Children:
7204cb
Parents:
3c9c29
Message:

code formatting (no code changes)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • modules/vI_log.js

    r3c9c29 r509348  
    2525var EXPORTED_SYMBOLS = ["setupLogging", "dumpCallStack", "MyLog", "Colors",
    2626  "clearDebugOutput", "notificationOverflow",
    27   "SmartReplyNotification", "StorageNotification", "GetHeaderNotification" ]
    28 
    29 const {classes: Cc, interfaces: Ci, utils: Cu, results : Cr} = Components;
     27  "SmartReplyNotification", "StorageNotification", "GetHeaderNotification"
     28]
     29
     30const {
     31  classes: Cc,
     32  interfaces: Ci,
     33  utils: Cu,
     34  results: Cr
     35} = Components;
    3036Cu.import("resource:///modules/gloda/log4moz.js");
    3137Cu.import("resource://v_identity/vI_prefs.js");
     
    5258
    5359  shutdown: function () {
    54       try {
    55         Services.console.unregisterListener(this);
    56         Services.obs.removeObserver(this, "quit-application");
    57       } catch (e) { };
     60    try {
     61      Services.console.unregisterListener(this);
     62      Services.obs.removeObserver(this, "quit-application");
     63    } catch (e) {};
    5864  },
    5965
     
    6672    try {
    6773      if ((aMessage instanceof Components.interfaces.nsIScriptError) &&
    68         (aMessage.sourceName.contains("v_identity")) &&
    69         (!aMessage.errorMessage.contains("Error console says")))
    70         {
    71             MyLog.info("Error console says" + aMessage);
    72         }
    73     }
    74     catch (ex) {
     74        (aMessage.sourceName.contains("v_identity")) &&
     75        (!aMessage.errorMessage.contains("Error console says"))) {
     76        MyLog.info("Error console says" + aMessage);
     77      }
     78    } catch (ex) {
    7579      // This is to avoid pathological error loops.  we definitely do not
    7680      // want to propagate an error here.
     
    8993    //  undefined.
    9094    let messageString = [
    91       ("" + mo) for each
    92       ([,mo] in Iterator(message.messageObjects))].join(" ");
     95      ("" + mo) for each([, mo] in Iterator(message.messageObjects))
     96    ].join(" ");
    9397    return messageString;
    9498  }
     
    104108    //  undefined.
    105109    let messageString = [
    106       ("" + mo) for each
    107       ([,mo] in Iterator(message.messageObjects))].join(" ");
    108     return message.loggerName.replace("virtualIdentity.", "") + ":\t" + messageString  + "\n";
     110      ("" + mo) for each([, mo] in Iterator(message.messageObjects))
     111    ].join(" ");
     112    return message.loggerName.replace("virtualIdentity.", "") + ":\t" + messageString + "\n";
    109113  }
    110114};
     
    121125  __proto__: Log4Moz.Appender.prototype,
    122126
    123   currentWindow : null,
    124  
     127  currentWindow: null,
     128
    125129  doAppend: function DOApp_doAppend(message) {
    126130    if (!vIprefs.get("debug_notification")) return;
     
    144148NotificationOutputAppender.prototype = {
    145149  __proto__: Log4Moz.Appender.prototype,
    146  
    147   currentWindow : null,
     150
     151  currentWindow: null,
    148152
    149153  doAppend: function DOApp_doAppend(message) {
     
    154158      this.addNote(message);
    155159  },
    156  
    157   timer : null,
    158 
    159   clearNote: function(self) {
     160
     161  timer: null,
     162
     163  clearNote: function (self) {
    160164    if (self.timer)
    161165      self.currentWindow.clearTimeout(self.timer);
     
    166170  },
    167171
    168   addNote: function(note) {
     172  addNote: function (note) {
    169173    let obj_notificationBox = this.currentWindow.document.getElementById("virtualIdentityExtension_vINotification");
    170174    if (!obj_notificationBox)
    171175      return;
    172176    let oldNotification = obj_notificationBox.currentNotification
    173     let newLabel = (oldNotification)?oldNotification.label + note:note;
     177    let newLabel = (oldNotification) ? oldNotification.label + note : note;
    174178    this.clearNote(this);
    175179    obj_notificationBox.appendNotification(newLabel, "", "chrome://messenger/skin/icons/flag.png");
     
    177181    if (vIprefs.get("notification_timeout") != 0)
    178182      this.timer =
    179         this.currentWindow.setTimeout(this.clearNote,
    180                                       vIprefs.get("notification_timeout") * 1000, this);
     183      this.currentWindow.setTimeout(this.clearNote,
     184        vIprefs.get("notification_timeout") * 1000, this);
    181185  }
    182186}
     
    189193  // height will be cut off from messagepane (in 3pane window)
    190194  let objMessagepane = currentWindow.document.getElementById("messagepane");
    191   let maxHeight = (objMessagepane)?parseInt(objMessagepane.boxObject.height / 2)+1:null;
     195  let maxHeight = (objMessagepane) ? parseInt(objMessagepane.boxObject.height / 2) + 1 : null;
    192196  if (maxHeight < 60) maxHeight = 60; // set a minimum size, if to small scrollbars are hidden
    193     let tooBig = (maxHeight)?(elem.inputField.scrollHeight > maxHeight):false;
    194     let newHeight = (tooBig)?maxHeight:elem.inputField.scrollHeight;
    195     elem.height = newHeight;
     197  let tooBig = (maxHeight) ? (elem.inputField.scrollHeight > maxHeight) : false;
     198  let newHeight = (tooBig) ? maxHeight : elem.inputField.scrollHeight;
     199  elem.height = newHeight;
    196200  // give the box a frame if it is to big
    197201  if (tooBig)
    198202    var notificationBox = currentWindow.document.getElementById("virtualIdentityExtension_vINotificationTextbox");
    199     if (notificationBox) notificationBox.setAttribute("class", "plain border");
     203  if (notificationBox) notificationBox.setAttribute("class", "plain border");
    200204}
    201205
     
    265269
    266270function _startFileLogging() {
    267     var file = Components.classes["@mozilla.org/file/local;1"]
    268         .createInstance(Components.interfaces.nsIFile);
    269 
    270     var defaultPath = Components.classes["@mozilla.org/file/directory_service;1"]
    271                 .getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile).path;
    272 
     271  var file = Components.classes["@mozilla.org/file/local;1"]
     272    .createInstance(Components.interfaces.nsIFile);
     273
     274  var defaultPath = Components.classes["@mozilla.org/file/directory_service;1"]
     275    .getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile).path;
     276
     277  try {
     278    file.initWithPath(vIprefs.get("debug_to_file_path"));
     279  } catch (NS_ERROR_FILE_UNRECOGNIZED_PATH) {
    273280    try {
    274         file.initWithPath(vIprefs.get("debug_to_file_path"));
     281      // try linux delimiter
     282      file.initWithPath(defaultPath + "/" + vIprefs.get("debug_to_file_path"));
     283    } catch (NS_ERROR_FILE_UNRECOGNIZED_PATH) {
     284      try {
     285        // use windows delimiter
     286        file.initWithPath(defaultPath + "\\" + vIprefs.get("debug_to_file_path"));
     287      } catch (NS_ERROR_FILE_UNRECOGNIZED_PATH) {
     288        dump("FileAppender not available for logging: set logging file first\n");
     289      };
    275290    }
    276     catch(NS_ERROR_FILE_UNRECOGNIZED_PATH) {
    277         try {
    278             // try linux delimiter
    279             file.initWithPath(defaultPath + "/" + vIprefs.get("debug_to_file_path"));
    280         } catch (NS_ERROR_FILE_UNRECOGNIZED_PATH) {
    281             try {
    282                 // use windows delimiter
    283                 file.initWithPath(defaultPath + "\\" + vIprefs.get("debug_to_file_path"));
    284             } catch (NS_ERROR_FILE_UNRECOGNIZED_PATH) {
    285                 dump("FileAppender not available for logging: set logging file first\n");
    286             };
    287         }
    288     }
    289     // A dump appender outputs to File
    290     DebugFileAppender = new Log4Moz.FileAppender(file);
    291 
    292     if (DebugFileAppender.doAppend.toString().indexOf("this._fos().write") > -1) {
    293         dump("*** hot-fixing FileAppender Logging Bug (https://bugzilla.mozilla.org/show_bug.cgi?id=1082551)\n");
    294         // there is a bug in original implementation of doAppend, fix the issue
    295         DebugFileAppender.doAppend = function FApp_doAppend(message) {
    296             if (message === null || message.length <= 0)
    297                 return;
    298             try {
    299                 this._fos.write(message, message.length);
    300             } catch(e) {
    301                 dump("Error writing file:\n" + e);
    302             }
    303         };
    304     }
    305 
    306     DebugFileAppender.level = Log4Moz.Level["All"];
    307     Log4Moz.repository.rootLogger.addAppender(DebugFileAppender);
    308    
    309     _errorConsoleTunnel.initialize();
     291  }
     292  // A dump appender outputs to File
     293  DebugFileAppender = new Log4Moz.FileAppender(file);
     294
     295  if (DebugFileAppender.doAppend.toString().indexOf("this._fos().write") > -1) {
     296    dump("*** hot-fixing FileAppender Logging Bug (https://bugzilla.mozilla.org/show_bug.cgi?id=1082551)\n");
     297    // there is a bug in original implementation of doAppend, fix the issue
     298    DebugFileAppender.doAppend = function FApp_doAppend(message) {
     299      if (message === null || message.length <= 0)
     300        return;
     301      try {
     302        this._fos.write(message, message.length);
     303      } catch (e) {
     304        dump("Error writing file:\n" + e);
     305      }
     306    };
     307  }
     308
     309  DebugFileAppender.level = Log4Moz.Level["All"];
     310  Log4Moz.repository.rootLogger.addAppender(DebugFileAppender);
     311
     312  _errorConsoleTunnel.initialize();
    310313}
    311314
    312315function _stopFileLogging() {
    313     if (DebugFileAppender)
    314         Log4Moz.repository.rootLogger.removeAppender(DebugFileAppender);
    315     _errorConsoleTunnel.shutdown();
     316  if (DebugFileAppender)
     317    Log4Moz.repository.rootLogger.removeAppender(DebugFileAppender);
     318  _errorConsoleTunnel.shutdown();
    316319}
    317320
    318321function _dump_extension_list() {
    319     Components.utils.import("resource://gre/modules/AddonManager.jsm");
    320     AddonManager.getAllAddons(function(addons) {
    321         var strings = addons.map(function(addon) {
    322             return (addon.userDisabled || addon.appDisabled ? "" : "addon: " + addon.name + " " + addon.version + "\n");
    323         });
    324         MyLog.info("\n--------------------------------------------------------------------------------\n" +
    325             strings.join("") +
    326             "--------------------------------------------------------------------------------");
    327         });
     322  Components.utils.import("resource://gre/modules/AddonManager.jsm");
     323  AddonManager.getAllAddons(function (addons) {
     324    var strings = addons.map(function (addon) {
     325      return (addon.userDisabled || addon.appDisabled ? "" : "addon: " + addon.name + " " + addon.version + "\n");
     326    });
     327    MyLog.info("\n--------------------------------------------------------------------------------\n" +
     328      strings.join("") +
     329      "--------------------------------------------------------------------------------");
     330  });
    328331}
    329332
    330333function _dump_info_block() {
    331     // add some information about the mail-client and the extensions installed
    332     if ("@mozilla.org/xre/app-info;1" in Components.classes) {
    333         var appInfo = Components.classes["@mozilla.org/xre/app-info;1"]
    334             .getService(Components.interfaces.nsIXULAppInfo);
    335         var protohandler = Components.classes["@mozilla.org/network/protocol;1?name=http"]
    336             .getService(Components.interfaces.nsIHttpProtocolHandler);
    337         MyLog.info("start logging for new session\n--------------------------------------------------------------------------------\n" +
    338             appInfo.name + " " + appInfo.version + " (" + appInfo.appBuildID + "; " + protohandler.oscpu + ")\n" +
    339             "--------------------------------------------------------------------------------");
    340     }
    341     else
    342         MyLog.info("\n--------------------------------------------------------------------------------\n" +
    343             "mail-client seems not supported by Virtual Identity Extension\n" +
    344             "--------------------------------------------------------------------------------");
    345    
    346     _dump_extension_list();
     334  // add some information about the mail-client and the extensions installed
     335  if ("@mozilla.org/xre/app-info;1" in Components.classes) {
     336    var appInfo = Components.classes["@mozilla.org/xre/app-info;1"]
     337      .getService(Components.interfaces.nsIXULAppInfo);
     338    var protohandler = Components.classes["@mozilla.org/network/protocol;1?name=http"]
     339      .getService(Components.interfaces.nsIHttpProtocolHandler);
     340    MyLog.info("start logging for new session\n--------------------------------------------------------------------------------\n" +
     341      appInfo.name + " " + appInfo.version + " (" + appInfo.appBuildID + "; " + protohandler.oscpu + ")\n" +
     342      "--------------------------------------------------------------------------------");
     343  } else
     344    MyLog.info("\n--------------------------------------------------------------------------------\n" +
     345      "mail-client seems not supported by Virtual Identity Extension\n" +
     346      "--------------------------------------------------------------------------------");
     347
     348  _dump_extension_list();
    347349}
    348350
    349351function UpdateFileLoggerPath() {
    350     dump("UpdateFileLoggerPath\n");
    351     if (vIprefs.get("debug_to_file")) {
    352         _stopFileLogging();
    353         _startFileLogging();
    354         _dump_info_block();
    355     }
    356 }   
     352  dump("UpdateFileLoggerPath\n");
     353  if (vIprefs.get("debug_to_file")) {
     354    _stopFileLogging();
     355    _startFileLogging();
     356    _dump_info_block();
     357  }
     358}
    357359
    358360function UpdateFileLogger() {
    359     if (vIprefs.get("debug_to_file")) {
    360         _startFileLogging();
    361         _dump_info_block();
    362     }
    363     else {
    364         _stopFileLogging();
    365     }
     361  if (vIprefs.get("debug_to_file")) {
     362    _startFileLogging();
     363    _dump_info_block();
     364  } else {
     365    _stopFileLogging();
     366  }
    366367}
    367368
    368369function UpdateSmartReplyNotification() {
    369     if (vIprefs.get("smart_reply_notification")) {
    370         SmartReplyAppender = new NotificationOutputAppender(myNotificationFormatter);
    371         SmartReplyAppender.level = Log4Moz.Level["All"];
    372         SmartReplyNotification.addAppender(SmartReplyAppender);
    373     }
    374     else {
    375         SmartReplyNotification.removeAppender(SmartReplyAppender);
    376     }
     370  if (vIprefs.get("smart_reply_notification")) {
     371    SmartReplyAppender = new NotificationOutputAppender(myNotificationFormatter);
     372    SmartReplyAppender.level = Log4Moz.Level["All"];
     373    SmartReplyNotification.addAppender(SmartReplyAppender);
     374  } else {
     375    SmartReplyNotification.removeAppender(SmartReplyAppender);
     376  }
    377377}
    378378
    379379function UpdateStorageNotification() {
    380     if (vIprefs.get("storage_notification")) {
    381         StorageAppender = new NotificationOutputAppender(myNotificationFormatter);
    382         StorageAppender.level = Log4Moz.Level["All"];
    383         StorageNotification.addAppender(StorageAppender);
    384     }
    385     else {
    386         StorageNotification.removeAppender(StorageAppender);
    387     }
     380  if (vIprefs.get("storage_notification")) {
     381    StorageAppender = new NotificationOutputAppender(myNotificationFormatter);
     382    StorageAppender.level = Log4Moz.Level["All"];
     383    StorageNotification.addAppender(StorageAppender);
     384  } else {
     385    StorageNotification.removeAppender(StorageAppender);
     386  }
    388387}
    389388
    390389function UpdateGetHeaderNotification() {
    391     if (vIprefs.get("get_header_notification")) {
    392         GetHeaderAppender = new NotificationOutputAppender(myNotificationFormatter);
    393         GetHeaderAppender.level = Log4Moz.Level["All"];
    394         GetHeaderNotification.addAppender(GetHeaderAppender);
    395     }
    396     else {
    397         GetHeaderNotification.removeAppender(GetHeaderAppender);
    398     }
     390  if (vIprefs.get("get_header_notification")) {
     391    GetHeaderAppender = new NotificationOutputAppender(myNotificationFormatter);
     392    GetHeaderAppender.level = Log4Moz.Level["All"];
     393    GetHeaderNotification.addAppender(GetHeaderAppender);
     394  } else {
     395    GetHeaderNotification.removeAppender(GetHeaderAppender);
     396  }
    399397}
    400398
Note: See TracChangeset for help on using the changeset viewer.