зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1828392 - [remote] Fix Log helpers isTrace/DebugLevelOrAbove r=webdriver-reviewers,whimboo
Differential Revision: https://phabricator.services.mozilla.com/D175606
This commit is contained in:
Родитель
fe6a89a7d7
Коммит
00c6191e69
|
@ -26,7 +26,7 @@ export class MarionetteEventsChild extends JSWindowActorChild {
|
|||
// Prevent the logger from being created if the current log level
|
||||
// isn't set to 'trace'. This is important for a faster content process
|
||||
// creation when Marionette is running.
|
||||
if (lazy.Log.isTraceLevelOrAbove) {
|
||||
if (lazy.Log.isTraceLevelOrOrMore) {
|
||||
lazy.logger.trace(
|
||||
`[${this.browsingContext.id}] MarionetteEvents actor created ` +
|
||||
`for window id ${this.innerWindowId}`
|
||||
|
|
|
@ -2,10 +2,21 @@
|
|||
* 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/. */
|
||||
|
||||
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
|
||||
|
||||
import { Log as StdLog } from "resource://gre/modules/Log.sys.mjs";
|
||||
|
||||
const PREF_REMOTE_LOG_LEVEL = "remote.log.level";
|
||||
|
||||
const lazy = {};
|
||||
|
||||
// Lazy getter which returns a cached value of the remote log level. Should be
|
||||
// used for static getters used to guard hot paths for logging, eg
|
||||
// isTraceLevelOrMore.
|
||||
XPCOMUtils.defineLazyGetter(lazy, "logLevel", () =>
|
||||
Services.prefs.getCharPref(PREF_REMOTE_LOG_LEVEL, StdLog.Level.Fatal)
|
||||
);
|
||||
|
||||
/** E10s compatible wrapper for the standard logger from Log.sys.mjs. */
|
||||
export class Log {
|
||||
static TYPES = {
|
||||
|
@ -38,10 +49,9 @@ export class Log {
|
|||
* above that. This should be used to guard logger.debug calls and avoid
|
||||
* instanciating logger instances unnecessarily.
|
||||
*/
|
||||
static get isDebugLevelOrAbove() {
|
||||
return [StdLog.Level.All, StdLog.Level.Trace, StdLog.Level.Debug].includes(
|
||||
PREF_REMOTE_LOG_LEVEL
|
||||
);
|
||||
static get isDebugLevelOrMore() {
|
||||
// Debug is assigned 20, more verbose log levels have lower values.
|
||||
return StdLog.Level[lazy.logLevel] <= StdLog.Level.Debug;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,10 +59,9 @@ export class Log {
|
|||
* above that. This should be used to guard logger.trace calls and avoid
|
||||
* instanciating logger instances unnecessarily.
|
||||
*/
|
||||
static get isTraceLevelOrAbove() {
|
||||
return [StdLog.Level.All, StdLog.Level.Trace].includes(
|
||||
PREF_REMOTE_LOG_LEVEL
|
||||
);
|
||||
static get isTraceLevelOrMore() {
|
||||
// Trace is assigned 10, more verbose log levels have lower values.
|
||||
return StdLog.Level[lazy.logLevel] <= StdLog.Level.Trace;
|
||||
}
|
||||
|
||||
static get verbose() {
|
||||
|
|
|
@ -39,7 +39,7 @@ export class WebSocketConnection {
|
|||
}
|
||||
|
||||
_log(direction, data) {
|
||||
if (lazy.Log.isDebugLevelOrAbove) {
|
||||
if (lazy.Log.isDebugLevelOrMore) {
|
||||
function replacer(key, value) {
|
||||
if (typeof value === "string") {
|
||||
return lazy.truncate`${value}`;
|
||||
|
|
Загрузка…
Ссылка в новой задаче