Repository: wix/Detox
Pull request #2642 (2021-02-15 16:53:35)

Clean up default log printing to prevent clutter
This will be the default output:
<img width="1202" alt="Good" src="https://user-images.githubusercontent.com/2270433/107978479-81b07e00-6fc5-11eb-992e-0018e0f54307.png">

Instead of:
<img width="1228" alt="Bad" src="https://user-images.githubusercontent.com/2270433/107977511-e8cd3300-6fc3-11eb-8291-56519fa655fe.png">


LeoNatan: Let me encode the gif, and then merge.

Patch:
diff --git a/README.md b/README.md
index 3442fbcb4..042430a0e 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
 <p align="center">
-	<img alt="Detox" width=380 src="https://raw.githubusercontent.com/wix/Detox/master/docs/img/DetoxLogo.png"/>
+	<img alt="Detox" width=380 src="docs/img/DetoxLogo.png"/>
 </p>
 <h1 align="center">
   Detox
@@ -8,10 +8,11 @@
 <b>Gray box end-to-end testing and automation library for mobile apps.</b>
 </p>
 <p align="center">
-<img alt="Demo" src="http://i.imgur.com/eoaDEYp.gif"/>
+<img alt="Demo" src="docs/img/Detox.gif"/>
 </p>
 
 
+
 ---
 
 <img src="https://user-images.githubusercontent.com/1962469/89655670-1c235c80-d8d3-11ea-9320-0f865767ef5d.png" alt="" height=24 width=1> [![NPM Version](https://img.shields.io/npm/v/detox.svg?style=flat)](https://www.npmjs.com/package/detox) [![NPM Downloads](https://img.shields.io/npm/dm/detox.svg?style=flat)](https://www.npmjs.com/package/detox) [![Build Status](https://img.shields.io/jenkins/s/http/jenkins-oss.wixpress.com:8080/job/multi-detox-master.svg)](https://jenkins-oss.wixpress.com/job/multi-detox-master/) [![Coverage Status](https://coveralls.io/repos/github/wix/Detox/badge.svg?branch=master)](https://coveralls.io/github/wix/Detox?branch=master) [![Detox is released under the MIT license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![PR's welcome!](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](docs/Guide.Contributing.md) [![Twitter Follow](https://img.shields.io/twitter/follow/detoxe2e?label=Follow&style=social)](https://twitter.com/detoxe2e)
diff --git a/detox/runners/jest/SpecReporterImpl.js b/detox/runners/jest/SpecReporterImpl.js
index 5bebd2cab..0be084eca 100644
--- a/detox/runners/jest/SpecReporterImpl.js
+++ b/detox/runners/jest/SpecReporterImpl.js
@@ -1,6 +1,7 @@
 const chalk = require('chalk').default;
 const { traceln } = require('./utils/stdout');
-const log = require('../../src/utils/logger').child();
+const logger = require('../../src/utils/logger');
+const log = logger.child();
 
 const RESULT_SKIPPED = chalk.yellow('SKIPPED');
 const RESULT_FAILED = chalk.red('FAIL');
@@ -29,7 +30,9 @@ class SpecReporter {
   }
 
   onTestStart({description, invocations = 1}) {
-    this._traceTest({description, invocations});
+    if(/^(debug|trace)$/.test(logger.getDetoxLevel())) {
+      this._traceTest({description, invocations});
+    }
   }
 
   onTestEnd({description, invocations = 1}, result) {
@@ -58,11 +61,17 @@ class SpecReporter {
   }
 
   _traceTest({description, invocations}, _status = undefined) {
+    if(_status === RESULT_SKIPPED && !/^(debug|trace)$/.test(logger.getDetoxLevel())) {
+      return;
+    }
+    
     const testDescription = chalk.gray(description);
     const retriesDescription = (invocations > 1) ? chalk.gray(` [Retry #${invocations - 1}]`) : '';
     const status = chalk.gray(_status ? ` [${_status}]` : '');
     const desc = this._suitesDesc + testDescription + retriesDescription + status;
-    log.info({event: 'SPEC_STATE_CHANGE'}, desc);
+    
+    const loggingFunc = _status === RESULT_FAILED ? log.error.bind(log) : log.info.bind(log);
+    loggingFunc({event: 'SPEC_STATE_CHANGE'}, desc);
   }
 }
 
diff --git a/detox/runners/jest/WorkerAssignReporterImpl.js b/detox/runners/jest/WorkerAssignReporterImpl.js
index 0dc80f6d8..46457a965 100644
--- a/detox/runners/jest/WorkerAssignReporterImpl.js
+++ b/detox/runners/jest/WorkerAssignReporterImpl.js
@@ -13,7 +13,7 @@ class WorkerAssignReporterImpl {
       ? chalk.redBright('undefined')
       : chalk.blueBright(deviceName);
 
-    log.info({event: 'WORKER_ASSIGN'}, `${chalk.whiteBright(workerName)} is assigned to ${formattedDeviceName}`);
+    log.trace({event: 'WORKER_ASSIGN'}, `${chalk.whiteBright(workerName)} is assigned to ${formattedDeviceName}`);
   }
 }
 
diff --git a/detox/src/devices/drivers/ios/SimulatorDriver.js b/detox/src/devices/drivers/ios/SimulatorDriver.js
index 7e251a1c6..f12b6a89c 100644
--- a/detox/src/devices/drivers/ios/SimulatorDriver.js
+++ b/detox/src/devices/drivers/ios/SimulatorDriver.js
@@ -126,7 +126,7 @@ class SimulatorDriver extends IosDriver {
               `xcrun simctl spawn ${deviceId} launchctl list | grep -F '${bundleId}'\n`,
       });
     } else {
-      log.info({}, `Found the app (${bundleId}) with process ID = ${pid}. Proceeding...`);
+      log.debug({}, `Found the app (${bundleId}) with process ID = ${pid}. Proceeding...`);
     }
 
     await this.emitter.emit('launchApp', {bundleId, deviceId, launchArgs, pid});
diff --git a/detox/src/devices/drivers/ios/tools/AppleSimUtils.js b/detox/src/devices/drivers/ios/tools/AppleSimUtils.js
index c84dcc925..1caf7e8f1 100644
--- a/detox/src/devices/drivers/ios/tools/AppleSimUtils.js
+++ b/detox/src/devices/drivers/ios/tools/AppleSimUtils.js
@@ -351,7 +351,7 @@ class AppleSimUtils {
     const predicate = `process == "${CFBundleExecutable}"`;
     const command = `/usr/bin/xcrun simctl spawn ${udid} log stream --level debug --style compact --predicate '${predicate}'`;
 
-    log.info(`${bundleId} launched. To watch simulator logs, run:\n        ${command}`);
+    log.debug(`${bundleId} launched. To watch simulator logs, run:\n        ${command}`);
   }
 
   _parseLaunchId(result) {
diff --git a/detox/src/server/DetoxServer.js b/detox/src/server/DetoxServer.js
index 65cd3936b..ad33fae12 100644
--- a/detox/src/server/DetoxServer.js
+++ b/detox/src/server/DetoxServer.js
@@ -16,7 +16,7 @@ class DetoxServer {
     });
     this.sessions = {};
     this.standalone = standalone;
-    logger.info(`server listening on localhost:${this.wss.options.port}...`);
+    logger.debug(`server listening on localhost:${this.wss.options.port}...`);
     this._setup();
   }
 
diff --git a/detox/src/utils/customConsoleLogger.js b/detox/src/utils/customConsoleLogger.js
index e3ab4df49..498c80896 100644
--- a/detox/src/utils/customConsoleLogger.js
+++ b/detox/src/utils/customConsoleLogger.js
@@ -48,7 +48,7 @@ function overrideConsoleMethods(console, bunyanLogger) {
 
     override(console, 'log', log.info.bind(log));
     override(console, 'warn', log.warn.bind(log));
-    override(console, 'trace', log.info.bind(log));
+    override(console, 'trace', log.trace.bind(log));
     override(console, 'error', log.error.bind(log));
     override(console, 'debug', log.debug.bind(log));
     override(console, 'assert', log.error.bind(log));
diff --git a/detox/src/utils/logger.js b/detox/src/utils/logger.js
index 0d4f6132d..0a4a0a318 100644
--- a/detox/src/utils/logger.js
+++ b/detox/src/utils/logger.js
@@ -6,6 +6,7 @@ const bunyanDebugStream = require('bunyan-debug-stream');
 const argparse = require('./argparse');
 const temporaryPath = require('../artifacts/utils/temporaryPath');
 const customConsoleLogger = require('./customConsoleLogger');
+const isRunningInBand = !!global.DETOX_CLI || argparse.getArgValue('maxWorkers') == '1';
 
 function adaptLogLevelName(level) {
   switch (level) {
@@ -35,8 +36,8 @@ function tryOverrideConsole(logger, global) {
 function createPlainBunyanStream({ logPath, level }) {
   const options = {
     showDate: false,
-    showLoggerName: true,
-    showPid: true,
+    showLoggerName: !isRunningInBand,
+    showPid: !isRunningInBand,
     showMetadata: false,
     basepath: __dirname,
     out: process.stderr,


Test patch:
diff --git a/detox/local-cli/test.js b/detox/local-cli/test.js
index 6fe27fb34..9416746be 100644
--- a/detox/local-cli/test.js
+++ b/detox/local-cli/test.js
@@ -217,7 +217,7 @@ function launchTestRunner({ argv, env, specs }) {
     specs.join(' ')
   ].join(' ');
 
-  log.info(printEnvironmentVariables(env) + fullCommand);
+  log.debug(printEnvironmentVariables(env) + fullCommand);
 
   cp.execSync(fullCommand, {
     stdio: 'inherit',
diff --git a/detox/src/utils/customConsoleLogger.test.js b/detox/src/utils/customConsoleLogger.test.js
index d5fcd0215..68685fd71 100644
--- a/detox/src/utils/customConsoleLogger.test.js
+++ b/detox/src/utils/customConsoleLogger.test.js
@@ -17,10 +17,11 @@ describe('customConsoleLogger.overrideConsoleMethods(console, bunyanLogger)', ()
     };
 
     bunyanLogger = {
-      debug: jest.fn(),
+      error: jest.fn(),
       warn: jest.fn(),
       info: jest.fn(),
-      error: jest.fn(),
+      debug: jest.fn(),
+      trace: jest.fn(),
     };
   });
 
@@ -57,9 +58,9 @@ describe('customConsoleLogger.overrideConsoleMethods(console, bunyanLogger)', ()
       expect(bunyanLogger.warn).toHaveBeenCalledWith(USER_LOG_EVENT, expectedOrigin, '\n', 'Warning 301');
     });
 
-    it('should connect: console.trace -> logger.info', () => {
+    it('should connect: console.trace -> logger.trace', () => {
       fakeConsole.trace('TraceMe %d', 100500);
-      expect(bunyanLogger.info).toHaveBeenCalledWith(USER_LOG_EVENT, expectedOrigin, '\n  Trace:', 'TraceMe 100500', expectedStackDump);
+      expect(bunyanLogger.trace).toHaveBeenCalledWith(USER_LOG_EVENT, expectedOrigin, '\n  Trace:', 'TraceMe 100500', expectedStackDump);
     });
 
     it('should connect: console.error -> logger.error', () => {