Skip to content

Commit 35afd38

Browse files
Hypukfacebook-github-bot
authored andcommitted
Log debug messages using debug() instead of console.log()
Reviewed By: avp Differential Revision: D15029492 fbshipit-source-id: 2bfbe769f3623c8308050cdb11ebd6f9334bccaf
1 parent fa6195a commit 35afd38

File tree

4 files changed

+13
-24
lines changed

4 files changed

+13
-24
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"chalk": "^2.4.1",
2020
"chokidar": "^2.0.4",
2121
"codecov": "^2.2.0",
22+
"debug": "^2.2.0",
2223
"eslint": "5.1.0",
2324
"eslint-config-fb-strict": "22.1.0",
2425
"eslint-plugin-babel": "^5.2.1",

packages/metro-inspector-proxy/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
],
1818
"license": "MIT",
1919
"dependencies": {
20-
"chalk": "^2.4.1",
2120
"connect": "^3.6.5",
21+
"debug": "^2.2.0",
2222
"rxjs": "^5.4.3",
2323
"ws": "^1.1.5",
2424
"yargs": "^9.0.0"

packages/metro-inspector-proxy/src/Device.js

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import WS from 'ws';
1616

1717
const PAGES_POLLING_INTERVAL = 1000;
1818

19-
const chalk = require('chalk');
19+
const debug = require('debug')('Metro:InspectorProxy');
2020

2121
// Android's stock emulator and other emulators such as genymotion use a standard localhost alias.
2222
const EMULATOR_LOCALHOST_ADDRESSES: Array<string> = ['10.0.2.2', '10.0.3.2'];
@@ -64,8 +64,7 @@ class Device {
6464
this._deviceSocket.on('message', (message: string) => {
6565
const parsedMessage = JSON.parse(message);
6666
if (parsedMessage.event !== 'getPages') {
67-
// eslint-disable-next-line no-console
68-
console.log(chalk.yellow('<- From device: ' + message));
67+
debug('<- From device: ' + message);
6968
}
7069
this._handleMessageFromDevice(parsedMessage);
7170
});
@@ -96,10 +95,7 @@ class Device {
9695
socket,
9796
};
9897
this._debuggerConnections.set(pageId, debuggerInfo);
99-
// eslint-disable-next-line no-console
100-
console.log(
101-
`Got new debugger connection for page ${pageId} of ${this._name}`,
102-
);
98+
debug(`Got new debugger connection for page ${pageId} of ${this._name}`);
10399

104100
this._sendMessageToDevice({
105101
event: 'connect',
@@ -109,8 +105,7 @@ class Device {
109105
});
110106

111107
socket.on('message', (message: string) => {
112-
// eslint-disable-next-line no-console
113-
console.log(chalk.green('<- From debugger: ' + message));
108+
debug('<- From debugger: ' + message);
114109
const parsedMessage = JSON.parse(message);
115110
this._processMessageFromDebugger(parsedMessage, debuggerInfo);
116111

@@ -123,10 +118,7 @@ class Device {
123118
});
124119
});
125120
socket.on('close', () => {
126-
// eslint-disable-next-line no-console
127-
console.log(
128-
`Debugger for page ${pageId} and ${this._name} disconnected.`,
129-
);
121+
debug(`Debugger for page ${pageId} and ${this._name} disconnected.`);
130122
this._sendMessageToDevice({
131123
event: 'disconnect',
132124
payload: {
@@ -153,8 +145,7 @@ class Device {
153145
const debuggerInfo = this._debuggerConnections.get(pageId);
154146
const debuggerSocket = debuggerInfo ? debuggerInfo.socket : null;
155147
if (debuggerSocket && debuggerSocket.readyState == WS.OPEN) {
156-
// eslint-disable-next-line no-console
157-
console.log(chalk.green(`Page ${pageId} is reloading.`));
148+
debug(`Page ${pageId} is reloading.`);
158149
debuggerSocket.send(JSON.stringify({method: 'reload'}));
159150
}
160151
} else if (message.event === 'wrappedEvent') {
@@ -174,8 +165,7 @@ class Device {
174165
this._processMessageFromDevice(parsedPayload, debuggerInfo);
175166

176167
const messageToSend = JSON.stringify(parsedPayload);
177-
// eslint-disable-next-line no-console
178-
console.log(chalk.green('-> To debugger: ' + messageToSend));
168+
debug('-> To debugger: ' + messageToSend);
179169
debuggerSocket.send(messageToSend);
180170
}
181171
}
@@ -184,8 +174,7 @@ class Device {
184174
_sendMessageToDevice(message: MessageToDevice) {
185175
try {
186176
if (message.event !== 'getPages') {
187-
// eslint-disable-next-line no-console
188-
console.log(chalk.yellow('-> To device' + JSON.stringify(message)));
177+
debug('-> To device' + JSON.stringify(message));
189178
}
190179
this._deviceSocket.send(JSON.stringify(message));
191180
} catch (error) {}

packages/metro-inspector-proxy/src/InspectorProxy.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
const Device = require('./Device');
1414
const WS = require('ws');
1515

16+
const debug = require('debug')('Metro:InspectorProxy');
1617
const url = require('url');
1718

1819
import type {
@@ -165,13 +166,11 @@ class InspectorProxy {
165166
new Device(deviceId, deviceName, appName, socket),
166167
);
167168

168-
// eslint-disable-next-line no-console
169-
console.log(`Got new connection: device=${deviceName}, app=${appName}`);
169+
debug(`Got new connection: device=${deviceName}, app=${appName}`);
170170

171171
socket.on('close', () => {
172172
this._devices.delete(deviceId);
173-
// eslint-disable-next-line no-console
174-
console.log(`Device ${deviceName} disconnected.`);
173+
debug(`Device ${deviceName} disconnected.`);
175174
});
176175
} catch (e) {
177176
console.error('error', e);

0 commit comments

Comments
 (0)