Commit 07fda10d authored by Markus Weiland's avatar Markus Weiland Committed by GitHub

Merge pull request #202 from ExchangeCalendar/201

Improve logging
parents a42d64f5 5dcb6337
......@@ -52,6 +52,15 @@ reproduce and fix. Examples of helpful information are:
* List of running Thunderbird add-ons
* Log output
#### Obtaining log output
To obtain log output, ensure logging is turned on. This setting can be found
in the Thunderbird menu under `Tools -> Add-on Preferences -> Lightning ->
Exchange (EWS) -> Logging`. Assert the checkbox is set for `Log information
to the console and a file`. You can then find log output at the given
file path and in the Developer Toolbox console (`Thunderbird menu -> Tools ->
Developer Tools -> Developer Toolbox`).
### Patch the code
To help us to maintain the code, we will be thankful to follow these main
......@@ -72,6 +81,18 @@ repository.
Please help us to review your code by making multiple small pull
requests instead of big ones modifying big parts of the code.
#### Building component interface files
Whenever an `.idl` file is changed, it is necessary to regenerate the
corresponding binary `.xpt` interface file. To
do this, download and extract the
[Gecko SDK](https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Guide/Creating_components/Setting_up_the_Gecko_SDK).
Next, go to the SDK's `idl` folder and run `python ../sdk/bin/typelib.py
-o $FILE.xpt $FILE.idl` to generate the binary interface file (replace
`$FILE` with the full path to an actual file). This SDK tool called
`pyxpidl` is documented
[here](https://developer.mozilla.org/en-US/docs/Mozilla/XPIDL/pyxpidl).
### Translate
You are welcome to provide translation updates on our Transifex project:
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -84,10 +84,12 @@ exchWebService.debugPreferences = {
if (aCheckBox.checked) {
this.disableChildren(document.getElementById("exchangeWebService_debug_groupbox1"), false);
this.disableChildren(document.getElementById("exchangeWebService_debug_groupbox2"), false);
this.disableChildren(document.getElementById("exchangeWebService_debug_groupbox3"), false);
}
else {
this.disableChildren(document.getElementById("exchangeWebService_debug_groupbox1"), true);
this.disableChildren(document.getElementById("exchangeWebService_debug_groupbox2"), true);
this.disableChildren(document.getElementById("exchangeWebService_debug_groupbox3"), true);
}
},
......@@ -96,5 +98,4 @@ exchWebService.debugPreferences = {
logUrl.value = document.getElementById("extensions.1st-setup.debug.file").value;
return undefined;
},
}
};
......@@ -45,7 +45,7 @@
%preferencesDTD;
%dtd1;
]>
<?xml-stylesheet type="text/css" href="chrome://exchangecommon/skin/preferences.css"?>
<?xml-stylesheet type="text/css" href="chrome://exchangecommon/preferences.css"?>
<overlay id="exchangeWebService_debug_preferences_overlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
......@@ -113,7 +113,7 @@
<textbox id="exchangeWebService_preference_core_debuglevel_textbox"
preference="extensions.1st-setup.core.debuglevel"
increment="1"
min="0"
min="1"
max="2"
type="number" />
</hbox>
......
This diff is collapsed.
......@@ -61,60 +61,10 @@ exchWebService.commonFunctions = {
return aObj[this._keys[this._i++]];
}
};
},
/* copyCalendarSettings: function _copyCalendarSettings(aFromId, aToId)
{
var fromCalPrefs = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefService)
.getBranch("extensions.exchangecalendar@extensions.1st-setup.nl."+aFromId+".");
if (aToId == undefined) {
var toId = Cc["@1st-setup.nl/global/functions;1"].getService(Ci.mivFunctions).getUUID();
}
else {
var toId = aToId;
}
var toCalPrefs = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefService)
.getBranch("extensions.exchangecalendar@extensions.1st-setup.nl."+toId+".");
Cc["@1st-setup.nl/global/functions;1"].getService(Ci.mivFunctions).copyPreferences(fromCalPrefs, toCalPrefs);
toCalPrefs.deleteBranch("folderProperties");
fromCalPrefs = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefService)
.getBranch("calendar.registry."+aFromId+".");
toCalPrefs = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefService)
.getBranch("calendar.registry."+toId+".");
Cc["@1st-setup.nl/global/functions;1"].getService(Ci.mivFunctions).copyPreferences(fromCalPrefs, toCalPrefs);
return toId;
},
*/
/* addCalendarById: function _addCalendarById(aId)
{
var ioService = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
var tmpURI = ioService.newURI("https://auto/"+aId, null, null);
var calManager = Cc["@mozilla.org/calendar/manager;1"]
.getService(Ci.calICalendarManager);
var newCal = calManager.createCalendar("exchangecalendar", tmpURI);
newCal.id = aId;
calManager.registerCalendar(newCal);
},*/
}
}
};
var mivFunctions = Cc["@1st-setup.nl/global/functions;1"].getService(Ci.mivFunctions);
let mivFunctions = Cc["@1st-setup.nl/global/functions;1"].getService(Ci.mivFunctions);
exchWebService.commonFunctions.doEncodeFolderSpecialChars = mivFunctions.doEncodeFolderSpecialChars;
exchWebService.commonFunctions.encodeFolderSpecialChars = mivFunctions.encodeFolderSpecialChars;
exchWebService.commonFunctions.doDecodeFolderSpecialChars = mivFunctions.doDecodeFolderSpecialChars;
......@@ -130,8 +80,8 @@ exchWebService.commonFunctions.safeGetIntPref = mivFunctions.safeGetIntPref;
exchWebService.commonFunctions.getStringBundle = mivFunctions.getStringBundle;
exchWebService.commonFunctions.getString = mivFunctions.getString;
exchWebService.commonFunctions.getUUID = mivFunctions.getUUID;
exchWebService.commonFunctions.shouldLog = mivFunctions.shouldLog;
exchWebService.commonFunctions.LOG = mivFunctions.LOG;
exchWebService.commonFunctions.DEBUG = mivFunctions.DEBUG;
exchWebService.commonFunctions.writeToLogFile = mivFunctions.writeToLogFile;
exchWebService.commonFunctions.WARN = mivFunctions.WARN;
exchWebService.commonFunctions.ERROR = mivFunctions.ERROR;
......
......@@ -49,10 +49,10 @@ function mivExchangeItemsManager() {
.getBranch("extensions.exchangecalendar@extensions.1st-setup.nl.");
this._accountManager = Cc["@1st-setup.nl/exchange/accountmanager;1"]
.getService(Ci.mivExchangeAccountManager)
.getService(Ci.mivExchangeAccountManager);
this._loadBalancer = Cc["@1st-setup.nl/exchange/loadbalancer;1"]
.getService(Ci.mivExchangeLoadBalancer)
.getService(Ci.mivExchangeLoadBalancer);
this.uuid = this.globalFunctions.getUUID();
......@@ -169,7 +169,7 @@ mivExchangeItemsManager.prototype = {
},
// Internal Methods
reset: function reset {
reset: function _reset() {
if ((!this._exchangeAccount) || ((!this._folderBase) && (!this._folderId))) {
return;
}
......@@ -212,22 +212,10 @@ mivExchangeItemsManager.prototype = {
ecRequestError: function (aRequest, aCode, aMsg) {},
logInfo: function _logInfo(aMsg, aDebugLevel) {
logInfo: function _logInfo(aMsg) {
this.globalFunctions.LOG("mivExchangeItemsManager: " + aMsg);
return;
if (!aDebugLevel) aDebugLevel = 1;
var prefB = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefBranch);
this.debugLevel = this.globalFunctions.safeGetIntPref(prefB, "extensions.1st-setup.core.debuglevel", 0, true);
if (aDebugLevel <= this.debugLevel) {
this.globalFunctions.LOG("mivExchangeItemsManager: " + aMsg);
}
},
}
};
function NSGetFactory(cid) {
......
......@@ -56,10 +56,14 @@ interface mivFunctions : nsISupports
AUTF8String getUUID();
boolean shouldLog();
void setIsWriteLog(in boolean aIsWriteLog);
void setDebugLevel(in uint64_t aDebugLevel);
void LOG(in AUTF8String aArg);
void DEBUG(in AUTF8String aArg);
void writeToLogFile(in AUTF8String aString);
void WARN(in AUTF8String aMessage);
......
......@@ -29,6 +29,7 @@ var components = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/Console.jsm");
Cu.import("resource://exchangecommoninterfaces/xml2jxon/mivIxml2jxon.js");
Cu.import("resource://exchangecommoninterfaces/xml2json/xml2json.js");
......@@ -39,6 +40,10 @@ function mivFunctions() {
.getService(Ci.nsIDOMParser);
this.xmlSerializer = Cc["@mozilla.org/xmlextras/xmlserializer;1"]
.createInstance(Ci.nsIDOMSerializer);
let prefB = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
this.setIsWriteLog(this.safeGetBoolPref(prefB, "extensions.1st-setup.debug.log", false, true));
this.setDebugLevel(this.safeGetIntPref(prefB, "extensions.1st-setup.core.debuglevel", 0, true));
}
mivFunctions.prototype = {
......@@ -59,6 +64,8 @@ mivFunctions.prototype = {
classID: components.ID("{c7543f10-e2d1-44b3-ae37-9221e0d5b524}"),
contractID: "@1st-setup.nl/global/functions;1",
flags: Ci.nsIClassInfo.SINGLETON || Ci.nsIClassInfo.THREADSAFE,
isWriteLog: false,
debugLevel: 1,
doEncodeFolderSpecialChars: function _doEncodeFolderSpecialChars(str, r1) {
var result = str;
......@@ -225,13 +232,12 @@ mivFunctions.prototype = {
safeGetCharPref: function _safeGetCharPref(aBranch, aName, aDefaultValue, aCreateWhenNotAvailable) {
if (!aBranch) {
// return aDefaultValue;
var realBranche = this.getBranch(aName);
if (!realBranche.branch) {
let realBranch = this.getBranch(aName);
if (!realBranch.branch) {
return aDefaultValue;
}
aBranch = realBranche.branch;
aName = realBranche.name;
aBranch = realBranch.branch;
aName = realBranch.name;
}
if (!aCreateWhenNotAvailable) {
......@@ -257,13 +263,12 @@ mivFunctions.prototype = {
safeGetBoolPref: function _safeGetBoolPref(aBranch, aName, aDefaultValue, aCreateWhenNotAvailable) {
if (!aBranch) {
// return aDefaultValue;
var realBranche = this.getBranch(aName);
if (!realBranche.branch) {
let realBranch = this.getBranch(aName);
if (!realBranch.branch) {
return aDefaultValue;
}
aBranch = realBranche.branch;
aName = realBranche.name;
aBranch = realBranch.branch;
aName = realBranch.name;
}
if (!aCreateWhenNotAvailable) {
......@@ -289,13 +294,12 @@ mivFunctions.prototype = {
safeGetIntPref: function _safeGetIntPref(aBranch, aName, aDefaultValue, aCreateWhenNotAvailable) {
if (!aBranch) {
// return aDefaultValue;
var realBranche = this.getBranch(aName);
if (!realBranche.branch) {
let realBranch = this.getBranch(aName);
if (!realBranch.branch) {
return aDefaultValue;
}
aBranch = realBranche.branch;
aName = realBranche.name;
aBranch = realBranch.branch;
aName = realBranch.name;
}
if (!aCreateWhenNotAvailable) {
......@@ -380,18 +384,18 @@ mivFunctions.prototype = {
return this.uuidGen.generateUUID().toString().replace(/[{}]/g, '');
},
/* Shortcut to the console service */
getConsoleService: function _getConsoleService() {
return Cc["@mozilla.org/consoleservice;1"]
.getService(Ci.nsIConsoleService);
},
/****
**** debug code
****/
setIsWriteLog: function _setIsWriteLog(aIsWriteLog) {
this.isWriteLog = aIsWriteLog;
},
setDebugLevel: function _setDebugLevel(aDebugLevel) {
this.debugLevel = aDebugLevel;
},
/**
* 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.
......@@ -399,18 +403,29 @@ mivFunctions.prototype = {
* @param aArg either a string to log or an object whose entire set of
* properties should be logged.
*/
shouldLog: function _shouldLog() {
var prefB = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
return this.safeGetBoolPref(prefB, "extensions.1st-setup.debug.log", false, true);
},
LOG: function _LOG(aArg) {
if (!this.isWriteLog) {
return;
}
if (!this.shouldLog()) {
let output = this.convertArgToString(aArg);
console.log(output);
this.writeToLogFile(output);
},
DEBUG: function _DEBUG(aArg) {
if (!this.isWriteLog || this.debugLevel < 2) {
return;
}
let output = this.convertArgToString(aArg);
console.debug(output);
},
convertArgToString: function _convertArgToString(aArg) {
try {
this.ASSERT(aArg, "Bad log argument.", true);
}
......@@ -418,26 +433,20 @@ mivFunctions.prototype = {
aArg = exc;
}
var string;
// We should just dump() both String objects, and string primitives.
if (!(aArg instanceof String) && !(typeof (aArg) == "string")) {
var string = "1st-setup: Logging object...\n";
for (var prop in aArg) {
string += prop + ': ' + aArg[prop] + '\n';
let output;
if (!(aArg instanceof String) && !(typeof (aArg) === "string")) {
output = "1st-setup: Logging object...\n";
for (let prop in aArg) {
output += prop + ': ' + aArg[prop] + '\n';
}
string += "End object\n";
output += "End object\n";
}
else {
var dt = new Date();
string = "ExchangeCalendar [" + dt.toISOString() + "]: " + aArg;
let dt = new Date();
output = "ExchangeCalendar [" + dt.toISOString() + "]: " + aArg;
}
// xxx todo consider using function debug()
dump(string + '\n');
this.getConsoleService().logStringMessage(string);
this.writeToLogFile(string);
return output;
},
writeToLogFile: function _writeToLogFile(aString) {
......@@ -446,8 +455,6 @@ mivFunctions.prototype = {
var file = this.safeGetCharPref(prefB, "extensions.1st-setup.debug.file", "/tmp/exchangecalendar.log", true);
if (file != "") {
// file is nsIFile, data is a string
//this.getConsoleService().logStringMessage(" >>>>>>>>>>>>>>>");
var localFile = Cc["@mozilla.org/file/local;1"]
.createInstance(Ci.nsIFile);
......@@ -491,13 +498,12 @@ mivFunctions.prototype = {
* @param aMessage warning message
*/
WARN: function _WARN(aMessage) {
dump("1st-setup: Warning: " + aMessage + '\n');
var scriptError = Cc["@mozilla.org/scripterror;1"]
.createInstance(Ci.nsIScriptError);
console.warn("1st-setup: Warning: " + aMessage + '\n');
var scriptError = Cc["@mozilla.org/scripterror;1"].createInstance(Ci.nsIScriptError);
scriptError.init("1st-setup: " + aMessage, null, null, 0, 0,
Ci.nsIScriptError.warningFlag,
"component javascript");
this.getConsoleService().logMessage(scriptError);
console.warn(scriptError);
},
/**
......@@ -506,13 +512,12 @@ mivFunctions.prototype = {
* @param aMessage error message
*/
ERROR: function _ERROR(aMessage) {
dump("1st-setup: Error: " + aMessage + '\n');
var scriptError = Cc["@mozilla.org/scripterror;1"]
.createInstance(Ci.nsIScriptError);
console.error("1st-setup: Error: " + aMessage + '\n');
var scriptError = Cc["@mozilla.org/scripterror;1"].createInstance(Ci.nsIScriptError);
scriptError.init("1st-setup: " + aMessage, null, null, 0, 0,
Ci.nsIScriptError.errorFlag,
"component javascript");
this.getConsoleService().logMessage(scriptError);
console.error(scriptError);
},
/**
......@@ -869,8 +874,7 @@ mivFunctions.prototype = {
return this.xmlSerializer.serializeToString(parsedHtml);
},
}
};
function NSGetFactory(cid) {
......@@ -878,7 +882,6 @@ function NSGetFactory(cid) {
if (!NSGetFactory.mivFunctions) {
// Load main script from lightning that we need.
NSGetFactory.mivFunctions = XPCOMUtils.generateNSGetFactory([mivFunctions]);
}
}
......
interfaces mivFunctions.xpt
component {c7543f10-e2d1-44b3-ae37-9221e0d5b524} mivFunctions.js
contract @1st-setup.nl/global/functions;1 {c7543f10-e2d1-44b3-ae37-9221e0d5b524}
......@@ -5,7 +5,7 @@
<!ENTITY exchangeWebService.preferences.tab.debug "Logging">
<!ENTITY exchangeWebService.preference.debug.file "Log file location:">
<!ENTITY exchangeWebService.preference.network.debug.caption "Communication with Exchange server:">
<!ENTITY exchangeWebService.preference.debug.log.label "Log information to the console and/or a file">
<!ENTITY exchangeWebService.preference.debug.log.label "Log information to the console and a file">
<!ENTITY exchangeWebService.preference.debug.file.button "Browse">
<!ENTITY exchangeWebService.preference.network.debug.label "Log communication with Exchange server">
<!ENTITY exchangeWebService.preference.network.debuglevel.label1 "Log level">
......@@ -21,7 +21,7 @@
<!ENTITY exchangeWebService.preferences.titleWin "Exchange (EWS) Preferences">
<!ENTITY exchangeWebService.preference.core.debug.caption "Core provider object:">
<!ENTITY exchangeWebService.preference.core.debuglevel.label2 "0 = None, 1 = Basic information, 2 = Extended information">
<!ENTITY exchangeWebService.preference.core.debuglevel.label2 "1 = Basic information, 2 = Extended information">
<!ENTITY exchangeWebService.preferences.tab.cache "Caching">
<!ENTITY exchangeWebService.preference.cache.memory.label "Minimal temporary memory cache">
......
......@@ -5,7 +5,7 @@
<!ENTITY exchangeWebService.preferences.tab.debug "Logging">
<!ENTITY exchangeWebService.preference.debug.file "Log file location:">
<!ENTITY exchangeWebService.preference.network.debug.caption "Communication with Exchange server:">
<!ENTITY exchangeWebService.preference.debug.log.label "Log information to the console and/or a file">
<!ENTITY exchangeWebService.preference.debug.log.label "Log information to the console and a file">
<!ENTITY exchangeWebService.preference.debug.file.button "Browse">
<!ENTITY exchangeWebService.preference.network.debug.label "Log communication with Exchange server">
<!ENTITY exchangeWebService.preference.network.debuglevel.label1 "Log level">
......@@ -21,7 +21,7 @@
<!ENTITY exchangeWebService.preferences.titleWin "Exchange (EWS) Preferences">
<!ENTITY exchangeWebService.preference.core.debug.caption "Core provider object:">
<!ENTITY exchangeWebService.preference.core.debuglevel.label2 "0 = None, 1 = Basic information, 2 = Extended information">
<!ENTITY exchangeWebService.preference.core.debuglevel.label2 "1 = Basic information, 2 = Extended information">
<!ENTITY exchangeWebService.preferences.tab.cache "Caching">
<!ENTITY exchangeWebService.preference.cache.memory.label "Minimal temporary memory cache">
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment