Bug 1645729 - avoid printing a warning to the console about a log level's preference. r=rfkelly
authorMark Hammond <mhammond@skippinet.com.au>
Mon, 15 Jun 2020 04:51:02 +0000
changeset 535628 f05a0084c5f20abf47fa332ab5ec5c953ba48eb1
parent 535627 995cb36e46d49d74ec262dc7d85b4fb3497cd8f0
child 535629 f719a8ab74c6cb79b1ce477a09f83b21aedef4a9
push id37506
push userabutkovits@mozilla.com
push dateMon, 15 Jun 2020 09:26:24 +0000
treeherdermozilla-central@f05a0084c5f2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrfkelly
bugs1645729
milestone79.0a1
first release with
nightly linux32
f05a0084c5f2 / 79.0a1 / 20200615092624 / files
nightly linux64
f05a0084c5f2 / 79.0a1 / 20200615092624 / files
nightly mac
f05a0084c5f2 / 79.0a1 / 20200615092624 / files
nightly win32
f05a0084c5f2 / 79.0a1 / 20200615092624 / files
nightly win64
f05a0084c5f2 / 79.0a1 / 20200615092624 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1645729 - avoid printing a warning to the console about a log level's preference. r=rfkelly Specifically: > Log warning: The log 'Services.Common.RESTRequest' is configured to use the preference 'services.common.log.logger.rest.request' - you must adjust the level by setting this preference, not by using the level setter This is because the hawkrequest module attempts to explicitly set the level from the preference value, but these days Log.jsm manages that itself. Also skips obtaining the log itself until it's needed, as it almost never actually is. Differential Revision: https://phabricator.services.mozilla.com/D79633
services/common/hawkrequest.js
services/common/tests/unit/test_hawkrequest.js
--- a/services/common/hawkrequest.js
+++ b/services/common/hawkrequest.js
@@ -155,18 +155,16 @@ async function deriveHawkCredentials(tok
 // With hawk request, we send the user's accepted-languages with each request.
 // To keep the number of times we read this pref at a minimum, maintain the
 // preference in a stateful object that notices and updates itself when the
 // pref is changed.
 function Intl() {
   // We won't actually query the pref until the first time we need it
   this._accepted = "";
   this._everRead = false;
-  this._log = Log.repository.getLogger("Services.Common.RESTRequest");
-  this._log.level = Log.Level[Prefs.get("log.logger.rest.request")];
   this.init();
 }
 
 this.Intl.prototype = {
   init() {
     Services.prefs.addObserver("intl.accept_languages", this);
   },
 
@@ -181,17 +179,18 @@ this.Intl.prototype = {
   readPref() {
     this._everRead = true;
     try {
       this._accepted = Services.prefs.getComplexValue(
         "intl.accept_languages",
         Ci.nsIPrefLocalizedString
       ).data;
     } catch (err) {
-      this._log.error("Error reading intl.accept_languages pref", err);
+      let log = Log.repository.getLogger("Services.Common.RESTRequest");
+      log.error("Error reading intl.accept_languages pref", err);
     }
   },
 
   get accept_languages() {
     if (!this._everRead) {
       this.readPref();
     }
     return this._accepted;
--- a/services/common/tests/unit/test_hawkrequest.js
+++ b/services/common/tests/unit/test_hawkrequest.js
@@ -32,18 +32,20 @@ function do_register_cleanup() {
   Services.prefs.resetUserPrefs();
 
   // remove the pref change listener
   let hawk = new HAWKAuthenticatedRESTRequest("https://example.com");
   hawk._intl.uninit();
 }
 
 function run_test() {
-  Log.repository.getLogger("Services.Common.RESTRequest").level =
-    Log.Level.Trace;
+  Services.prefs.setStringPref(
+    "services.common.log.logger.rest.request",
+    "Trace"
+  );
   initTestLogging("Trace");
 
   run_next_test();
 }
 
 add_test(function test_intl_accept_language() {
   let testCount = 0;
   let languages = [