Bug 1470333: Part 2 - Avoid creating ConsoleAPI instances when debug logging is not enabled. r=MattN

MozReview-Commit-ID: Edck1SgCcDA

--HG--
extra : source : dbea1942a32f8bd565f3d500d79fa19db8916fcc
extra : absorb_source : e50ef26aa346f7890d135637411b8988925b9700
This commit is contained in:
Kris Maglione 2018-07-04 12:43:21 -07:00
Родитель 25544ae690
Коммит e1e8de61c8
2 изменённых файлов: 36 добавлений и 10 удалений

Просмотреть файл

@ -42,7 +42,6 @@ const whitelist = {
"resource://gre/modules/XPCOMUtils.jsm",
// Logging related
"resource://gre/modules/Console.jsm", // bug 1470333
"resource://gre/modules/Log.jsm",
// Session store

Просмотреть файл

@ -40,13 +40,19 @@ var LoginHelper = {
return this.debug ? "debug" : "warn";
};
// Create a new instance of the ConsoleAPI so we can control the maxLogLevel with a pref.
let ConsoleAPI = ChromeUtils.import("resource://gre/modules/Console.jsm", {}).ConsoleAPI;
let consoleOptions = {
maxLogLevel: getMaxLogLevel(),
prefix: aLogPrefix,
};
let logger = new ConsoleAPI(consoleOptions);
let logger;
function getConsole() {
if (!logger) {
// Create a new instance of the ConsoleAPI so we can control the maxLogLevel with a pref.
let ConsoleAPI = ChromeUtils.import("resource://gre/modules/Console.jsm", {}).ConsoleAPI;
let consoleOptions = {
maxLogLevel: getMaxLogLevel(),
prefix: aLogPrefix,
};
logger = new ConsoleAPI(consoleOptions);
}
return logger;
}
// Watch for pref changes and update this.debug and the maxLogLevel for created loggers
Services.prefs.addObserver("signon.", () => {
@ -54,10 +60,31 @@ var LoginHelper = {
this.formlessCaptureEnabled = Services.prefs.getBoolPref("signon.formlessCapture.enabled");
this.schemeUpgrades = Services.prefs.getBoolPref("signon.schemeUpgrades");
this.insecureAutofill = Services.prefs.getBoolPref("signon.autofillForms.http");
logger.maxLogLevel = getMaxLogLevel();
if (logger) {
logger.maxLogLevel = getMaxLogLevel();
}
});
return logger;
return {
log: (...args) => {
if (this.debug) {
getConsole().log(...args);
}
},
error: (...args) => {
getConsole().error(...args);
},
debug: (...args) => {
if (this.debug) {
getConsole().debug(...args);
}
},
warn: (...args) => {
if (this.debug) {
getConsole().warn(...args);
}
},
};
},
/**