remote/Log.jsm
author André Bargull <andre.bargull@gmail.com>
Wed, 24 Apr 2019 10:56:44 +0000
changeset 529501 4d2b87a7d2f9ff2a135e2793001d5d94fe08696f
parent 528327 45358a231fb38928efa37c1fd72cc0d21423ca70
child 541071 07ce31daca134d974d5d1ee2c86f6fdc307d9aa4
permissions -rw-r--r--
Bug 1544364: Throw an error when calling the transplant test-function on a sandbox global. r=jandem Differential Revision: https://phabricator.services.mozilla.com/D28475

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

var EXPORTED_SYMBOLS = ["Log"];

const {Log: StdLog} = ChromeUtils.import("resource://gre/modules/Log.jsm");
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");

const LOG_LEVEL = "remote.log.level";

/** E10s compatible wrapper for the standard logger from Log.jsm. */
class Log {
  static get() {
    const logger = StdLog.repository.getLogger("RemoteAgent");
    if (logger.ownAppenders.length == 0) {
      logger.addAppender(new StdLog.DumpAppender());
      logger.manageLevelFromPref(LOG_LEVEL);
    }
    return logger;
  }

  static get verbose() {
    // we can't use Preferences.jsm before first paint,
    // see ../browser/base/content/test/performance/browser_startup.js
    const level = Services.prefs.getStringPref(LOG_LEVEL, "Info");
    return StdLog.Level[level] >= StdLog.Level.Info;
  }
}