Bug 1702142 - [remote] Unify logging between Marionette and Remote Agent. r=remote-protocol-reviewers,jgraham
authorHenrik Skupin <mail@hskupin.info>
Tue, 06 Apr 2021 15:08:50 +0000
changeset 574559 842971ea2eca10628fea9aa224e751a1aff8b38f
parent 574558 813c7ce3607bb31a6054dae8b4fb24e6f2abfeb7
child 574560 bbfd6d1b4f0580a3d0a26ce8d841f6dee8efad1b
push id140244
push userhskupin@mozilla.com
push dateTue, 06 Apr 2021 15:11:16 +0000
treeherderautoland@842971ea2eca [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersremote-protocol-reviewers, jgraham
bugs1702142
milestone89.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 1702142 - [remote] Unify logging between Marionette and Remote Agent. r=remote-protocol-reviewers,jgraham Differential Revision: https://phabricator.services.mozilla.com/D110936
remote/cdp/Connection.jsm
remote/cdp/Error.jsm
remote/components/RemoteAgent.jsm
remote/shared/Format.jsm
--- a/remote/cdp/Connection.jsm
+++ b/remote/cdp/Connection.jsm
@@ -11,17 +11,17 @@ const { XPCOMUtils } = ChromeUtils.impor
 );
 
 XPCOMUtils.defineLazyModuleGetters(this, {
   Log: "chrome://remote/content/shared/Log.jsm",
   truncate: "chrome://remote/content/shared/Format.jsm",
   UnknownMethodError: "chrome://remote/content/cdp/Error.jsm",
 });
 
-XPCOMUtils.defineLazyGetter(this, "log", () => Log.get());
+XPCOMUtils.defineLazyGetter(this, "logger", () => Log.get());
 
 XPCOMUtils.defineLazyServiceGetter(
   this,
   "UUIDGen",
   "@mozilla.org/uuid-generator;1",
   "nsIUUIDGenerator"
 );
 
@@ -60,17 +60,17 @@ class Connection {
       }
       this.defaultSession = session;
     }
     this.sessions.set(session.id, session);
   }
 
   send(body) {
     const payload = JSON.stringify(body, null, Log.verbose ? "\t" : null);
-    log.trace(truncate`<-(connection ${this.id}) ${payload}`);
+    logger.trace(truncate`<-(connection ${this.id}) ${payload}`);
     this.transport.send(JSON.parse(payload));
   }
 
   /**
    * Send an error back to the client.
    *
    * @param Number id
    *        Id of the packet which lead to an error.
@@ -181,17 +181,17 @@ class Connection {
    * Receive a packet from the WebSocket layer.
    * This packet is sent by a CDP client and is meant to execute
    * a particular function on a given Domain.
    *
    * @param Object packet
    *        JSON-serializable object sent by the client
    */
   async onPacket(packet) {
-    log.trace(`(connection ${this.id})-> ${JSON.stringify(packet)}`);
+    logger.trace(`(connection ${this.id})-> ${JSON.stringify(packet)}`);
 
     try {
       const { id, method, params, sessionId } = packet;
 
       // First check for mandatory field in the packets
       if (typeof id == "undefined") {
         throw new TypeError("Message missing 'id' field");
       }
--- a/remote/cdp/Error.jsm
+++ b/remote/cdp/Error.jsm
@@ -16,33 +16,33 @@ const { XPCOMUtils } = ChromeUtils.impor
 );
 
 XPCOMUtils.defineLazyModuleGetters(this, {
   Services: "resource://gre/modules/Services.jsm",
 
   Log: "chrome://remote/content/shared/Log.jsm",
 });
 
-XPCOMUtils.defineLazyGetter(this, "log", () => Log.get());
+XPCOMUtils.defineLazyGetter(this, "logger", () => Log.get());
 
 class RemoteAgentError extends Error {
   constructor(message = "", cause = undefined) {
     cause = cause || message;
     super(cause);
 
     this.name = this.constructor.name;
     this.message = message;
     this.cause = cause;
 
     this.notify();
   }
 
   notify() {
     Cu.reportError(this);
-    log.error(this.toString({ stack: true }));
+    logger.error(this.toString({ stack: true }));
   }
 
   toString({ stack = false } = {}) {
     return RemoteAgentError.format(this, { stack });
   }
 
   static format(e, { stack = false } = {}) {
     return formatError(e, { stack });
@@ -89,17 +89,17 @@ class RemoteAgentError extends Error {
  */
 class FatalError extends RemoteAgentError {
   constructor(...args) {
     super(...args);
     this.quit();
   }
 
   notify() {
-    log.fatal(this.toString({ stack: true }));
+    logger.fatal(this.toString({ stack: true }));
   }
 
   quit(mode = Ci.nsIAppStartup.eForceQuit) {
     Services.startup.quit(mode);
   }
 }
 
 /** When an operation is not yet implemented. */
--- a/remote/components/RemoteAgent.jsm
+++ b/remote/components/RemoteAgent.jsm
@@ -16,17 +16,17 @@ XPCOMUtils.defineLazyModuleGetters(this,
   JSONHandler: "chrome://remote/content/cdp/JSONHandler.jsm",
   Log: "chrome://remote/content/shared/Log.jsm",
   Preferences: "resource://gre/modules/Preferences.jsm",
   RecommendedPreferences:
     "chrome://remote/content/cdp/RecommendedPreferences.jsm",
   TargetList: "chrome://remote/content/cdp/targets/TargetList.jsm",
 });
 
-XPCOMUtils.defineLazyGetter(this, "log", () => Log.get());
+XPCOMUtils.defineLazyGetter(this, "logger", () => Log.get());
 
 const ENABLED = "remote.enabled";
 const FORCE_LOCAL = "remote.force-local";
 
 const LOOPBACKS = ["localhost", "127.0.0.1", "[::1]"];
 
 class RemoteAgentClass {
   constructor() {
@@ -77,17 +77,17 @@ class RemoteAgentClass {
 
     // nsIServerSocket uses -1 for atomic port allocation
     if (port === 0) {
       port = -1;
     }
 
     for (let [k, v] of RecommendedPreferences) {
       if (!Preferences.isSet(k)) {
-        log.debug(`Setting recommended pref ${k} to ${v}`);
+        logger.debug(`Setting recommended pref ${k} to ${v}`);
         Preferences.set(k, v);
         this.alteredPrefs.add(k);
       }
     }
 
     this.server = new HttpServer();
     this.server.registerPrefixHandler("/json/", new JSONHandler(this));
 
@@ -113,40 +113,40 @@ class RemoteAgentClass {
       this.server._start(port, host);
       Services.obs.notifyObservers(
         null,
         "remote-listening",
         mainTarget.wsDebuggerURL
       );
     } catch (e) {
       await this.close();
-      log.error(`Unable to start remote agent: ${e.message}`, e);
+      logger.error(`Unable to start remote agent: ${e.message}`, e);
     }
   }
 
   close() {
     try {
       for (let k of this.alteredPrefs) {
-        log.debug(`Resetting recommended pref ${k}`);
+        logger.debug(`Resetting recommended pref ${k}`);
         Preferences.reset(k);
       }
       this.alteredPrefs.clear();
 
       // destroy targetList before stopping server,
       // otherwise the HTTP will fail to stop
       if (this.targetList) {
         this.targetList.destructor();
       }
 
       if (this.listening) {
         return this.server.stop();
       }
     } catch (e) {
       // this function must never fail
-      log.error("unable to stop listener", e);
+      logger.error("unable to stop listener", e);
     } finally {
       this.server = null;
       this.targetList = null;
     }
 
     return Promise.resolve();
   }
 
--- a/remote/shared/Format.jsm
+++ b/remote/shared/Format.jsm
@@ -11,17 +11,17 @@ const { XPCOMUtils } = ChromeUtils.impor
 );
 
 XPCOMUtils.defineLazyModuleGetters(this, {
   Services: "resource://gre/modules/Services.jsm",
 
   Log: "chrome://remote/content/shared/Log.jsm",
 });
 
-XPCOMUtils.defineLazyGetter(this, "log", () => Log.get());
+XPCOMUtils.defineLazyGetter(this, "logger", () => Log.get());
 
 const ELEMENT_NODE = 1;
 const MAX_STRING_LENGTH = 250;
 const PREF_TRUNCATE = "remote.log.truncate";
 
 /**
  * Pretty-print values passed to template strings.
  *
@@ -96,17 +96,17 @@ function pprint(ss, ...values) {
   let res = [];
   for (let i = 0; i < ss.length; i++) {
     res.push(ss[i]);
     if (i < values.length) {
       let s;
       try {
         s = pretty(values[i]);
       } catch (e) {
-        log.warn("Problem pretty printing:", e);
+        logger.warn("Problem pretty printing:", e);
         s = typeof values[i];
       }
       res.push(s);
     }
   }
   return res.join("");
 }