Bug 1134846 - Add helpers to create loggers that follow the signon.debug pref. r=dolske
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Mon, 16 Mar 2015 12:42:08 -0700
changeset 234025 438e73cdb24252ce6f89201d133756958b37480c
parent 234024 35a52bd476cb1bd4c36a6fdabc14f28a981597ad
child 234026 1cb5e49440edc8e2053c13e550bd42899f28aa4b
push id57019
push usercbook@mozilla.com
push dateTue, 17 Mar 2015 10:50:22 +0000
treeherdermozilla-inbound@15e49729e473 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdolske
bugs1134846
milestone39.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 1134846 - Add helpers to create loggers that follow the signon.debug pref. r=dolske
toolkit/components/passwordmgr/LoginHelper.jsm
--- a/toolkit/components/passwordmgr/LoginHelper.jsm
+++ b/toolkit/components/passwordmgr/LoginHelper.jsm
@@ -18,26 +18,54 @@ this.EXPORTED_SYMBOLS = [
   "LoginHelper",
 ];
 
 ////////////////////////////////////////////////////////////////////////////////
 //// Globals
 
 const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
 
+Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 ////////////////////////////////////////////////////////////////////////////////
 //// LoginHelper
 
 /**
  * Contains functions shared by different Login Manager components.
  */
 this.LoginHelper = {
   /**
+   * Warning: this only updates if a logger was created.
+   */
+  debug: Services.prefs.getBoolPref("signon.debug"),
+
+  createLogger(aLogPrefix) {
+    let getMaxLogLevel = () => {
+      return this.debug ? "debug" : "error";
+    };
+
+    // Create a new instance of the ConsoleAPI so we can control the maxLogLevel with a pref.
+    let ConsoleAPI = Cu.import("resource://gre/modules/devtools/Console.jsm", {}).ConsoleAPI;
+    let consoleOptions = {
+      maxLogLevel: getMaxLogLevel(),
+      prefix: aLogPrefix,
+    };
+    let logger = new ConsoleAPI(consoleOptions);
+
+    // Watch for pref changes and update this.debug and the maxLogLevel for created loggers
+    Services.prefs.addObserver("signon.", () => {
+      this.debug = Services.prefs.getBoolPref("signon.debug");
+      logger.maxLogLevel = getMaxLogLevel();
+    }, false);
+
+    return logger;
+  },
+
+  /**
    * Due to the way the signons2.txt file is formatted, we need to make
    * sure certain field values or characters do not cause the file to
    * be parsed incorrectly.  Reject hostnames that we can't store correctly.
    *
    * @throws String with English message in case validation failed.
    */
   checkHostnameValue: function (aHostname)
   {