Changeset 509348 for modules/vI_log.js
- Timestamp:
- Nov 3, 2014, 12:35:40 PM (8 years ago)
- Branches:
- ng_0.9
- Children:
- 7204cb
- Parents:
- 3c9c29
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
modules/vI_log.js
r3c9c29 r509348 25 25 var EXPORTED_SYMBOLS = ["setupLogging", "dumpCallStack", "MyLog", "Colors", 26 26 "clearDebugOutput", "notificationOverflow", 27 "SmartReplyNotification", "StorageNotification", "GetHeaderNotification" ] 28 29 const {classes: Cc, interfaces: Ci, utils: Cu, results : Cr} = Components; 27 "SmartReplyNotification", "StorageNotification", "GetHeaderNotification" 28 ] 29 30 const { 31 classes: Cc, 32 interfaces: Ci, 33 utils: Cu, 34 results: Cr 35 } = Components; 30 36 Cu.import("resource:///modules/gloda/log4moz.js"); 31 37 Cu.import("resource://v_identity/vI_prefs.js"); … … 52 58 53 59 shutdown: function () { 54 55 56 57 } catch (e) {};60 try { 61 Services.console.unregisterListener(this); 62 Services.obs.removeObserver(this, "quit-application"); 63 } catch (e) {}; 58 64 }, 59 65 … … 66 72 try { 67 73 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) { 75 79 // This is to avoid pathological error loops. we definitely do not 76 80 // want to propagate an error here. … … 89 93 // undefined. 90 94 let messageString = [ 91 ("" + mo) for each 92 ([,mo] in Iterator(message.messageObjects))].join(" ");95 ("" + mo) for each([, mo] in Iterator(message.messageObjects)) 96 ].join(" "); 93 97 return messageString; 94 98 } … … 104 108 // undefined. 105 109 let messageString = [ 106 ("" + mo) for each 107 ([,mo] in Iterator(message.messageObjects))].join(" ");108 return message.loggerName.replace("virtualIdentity.", "") + ":\t" + messageString 110 ("" + mo) for each([, mo] in Iterator(message.messageObjects)) 111 ].join(" "); 112 return message.loggerName.replace("virtualIdentity.", "") + ":\t" + messageString + "\n"; 109 113 } 110 114 }; … … 121 125 __proto__: Log4Moz.Appender.prototype, 122 126 123 currentWindow 124 127 currentWindow: null, 128 125 129 doAppend: function DOApp_doAppend(message) { 126 130 if (!vIprefs.get("debug_notification")) return; … … 144 148 NotificationOutputAppender.prototype = { 145 149 __proto__: Log4Moz.Appender.prototype, 146 147 currentWindow 150 151 currentWindow: null, 148 152 149 153 doAppend: function DOApp_doAppend(message) { … … 154 158 this.addNote(message); 155 159 }, 156 157 timer 158 159 clearNote: function (self) {160 161 timer: null, 162 163 clearNote: function (self) { 160 164 if (self.timer) 161 165 self.currentWindow.clearTimeout(self.timer); … … 166 170 }, 167 171 168 addNote: function (note) {172 addNote: function (note) { 169 173 let obj_notificationBox = this.currentWindow.document.getElementById("virtualIdentityExtension_vINotification"); 170 174 if (!obj_notificationBox) 171 175 return; 172 176 let oldNotification = obj_notificationBox.currentNotification 173 let newLabel = (oldNotification) ?oldNotification.label + note:note;177 let newLabel = (oldNotification) ? oldNotification.label + note : note; 174 178 this.clearNote(this); 175 179 obj_notificationBox.appendNotification(newLabel, "", "chrome://messenger/skin/icons/flag.png"); … … 177 181 if (vIprefs.get("notification_timeout") != 0) 178 182 this.timer = 179 180 183 this.currentWindow.setTimeout(this.clearNote, 184 vIprefs.get("notification_timeout") * 1000, this); 181 185 } 182 186 } … … 189 193 // height will be cut off from messagepane (in 3pane window) 190 194 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; 192 196 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 197 let tooBig = (maxHeight) ? (elem.inputField.scrollHeight > maxHeight) : false; 198 let newHeight = (tooBig) ? maxHeight : elem.inputField.scrollHeight; 199 elem.height = newHeight; 196 200 // give the box a frame if it is to big 197 201 if (tooBig) 198 202 var notificationBox = currentWindow.document.getElementById("virtualIdentityExtension_vINotificationTextbox"); 199 203 if (notificationBox) notificationBox.setAttribute("class", "plain border"); 200 204 } 201 205 … … 265 269 266 270 function _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) { 273 280 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 }; 275 290 } 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(); 310 313 } 311 314 312 315 function _stopFileLogging() { 313 314 315 316 if (DebugFileAppender) 317 Log4Moz.repository.rootLogger.removeAppender(DebugFileAppender); 318 _errorConsoleTunnel.shutdown(); 316 319 } 317 320 318 321 function _dump_extension_list() { 319 320 AddonManager.getAllAddons(function(addons) {321 var strings = addons.map(function(addon) {322 323 324 325 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 }); 328 331 } 329 332 330 333 function _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(); 347 349 } 348 350 349 351 function UpdateFileLoggerPath() { 350 351 352 353 354 355 356 } 352 dump("UpdateFileLoggerPath\n"); 353 if (vIprefs.get("debug_to_file")) { 354 _stopFileLogging(); 355 _startFileLogging(); 356 _dump_info_block(); 357 } 358 } 357 359 358 360 function 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 } 366 367 } 367 368 368 369 function 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 } 377 377 } 378 378 379 379 function 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 } 388 387 } 389 388 390 389 function 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 } 399 397 } 400 398
Note: See TracChangeset
for help on using the changeset viewer.