Bug 1462725 - Add pref-controlled logging to Savant module; r=rhelmer
MozReview-Commit-ID: JFMo1s5lajo
--- a/browser/modules/ShieldStudySavant.jsm
+++ b/browser/modules/ShieldStudySavant.jsm
@@ -4,16 +4,29 @@
"use strict";
var EXPORTED_SYMBOLS = ["ShieldStudySavant"];
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm");
+// See LOG_LEVELS in Console.jsm. Examples: "all", "info", "warn", & "error".
+const PREF_LOG_LEVEL = "shield.savant.loglevel";
+
+// Create a new instance of the ConsoleAPI so we can control the maxLogLevel with a pref.
+XPCOMUtils.defineLazyGetter(this, "log", () => {
+ let ConsoleAPI = ChromeUtils.import("resource://gre/modules/Console.jsm", {}).ConsoleAPI;
+ let consoleOptions = {
+ maxLogLevelPref: PREF_LOG_LEVEL,
+ prefix: "ShieldStudySavant",
+ };
+ return new ConsoleAPI(consoleOptions);
+});
+
class ShieldStudySavantClass {
constructor() {
this.SHIELD_STUDY_SAVANT_PREF = "shield.savant.enabled";
}
init() {
// check the pref in case Normandy flipped it on before we could add the pref listener
this.shouldCollect = Services.prefs.getBoolPref(this.SHIELD_STUDY_SAVANT_PREF);
@@ -32,28 +45,31 @@ class ShieldStudySavantClass {
} else {
// Normandy has flipped off the pref
this.endStudy("expired");
}
}
}
enableCollection() {
+ log.debug("Study has been enabled; turning on data collection.");
// TODO: enable data collection
}
endStudy(reason) {
this.disableCollection();
// TODO: send endStudy ping with reason code
this.uninit();
}
disableCollection() {
+ log.debug("Study has been disabled; turning off data collection.");
// TODO: disable data collection
}
uninit() {
Services.prefs.removeObserver(this.SHIELD_STUDY_SAVANT_PREF, this);
Services.prefs.clearUserPref(this.SHIELD_STUDY_SAVANT_PREF);
+ Services.prefs.clearUserPref(PREF_LOG_LEVEL);
}
};
const ShieldStudySavant = new ShieldStudySavantClass();