remote/Log.jsm
author shindli <shindli@mozilla.com>
Mon, 22 Apr 2019 18:49:56 +0300
changeset 470376 b4b482a09cf0f1c7f31ee8d08266108f5d07d27e
parent 469510 45358a231fb38928efa37c1fd72cc0d21423ca70
child 481406 07ce31daca134d974d5d1ee2c86f6fdc307d9aa4
permissions -rw-r--r--
Merge mozilla-central to inbound. a=merge CLOSED TREE

/* 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;
  }
}