Bug 1462725 - Add pref-controlled logging to Savant module; r=rhelmer
authorBianca Danforth <bdanforth@mozilla.com>
Mon, 04 Jun 2018 16:18:39 -0700
changeset 421466 227bfae843a7fd7385a3fe243b1b3d7408e44e05
parent 421465 ac7e4d209fb44e1c4bafbe749385195bfda6e449
child 421467 cd6cbad8bafd25a28a308093eb802da9936c23c1
push id34095
push usernbeleuzu@mozilla.com
push dateWed, 06 Jun 2018 09:35:33 +0000
treeherdermozilla-central@d51b920aef69 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrhelmer
bugs1462725
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1462725 - Add pref-controlled logging to Savant module; r=rhelmer MozReview-Commit-ID: 7dIMl7vHGr6
browser/modules/ShieldStudySavant.jsm
--- 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();