diff --git a/packages/metro-runtime/src/modules/types.flow.js b/packages/metro-runtime/src/modules/types.flow.js index 8612c9713..539d8dbf3 100644 --- a/packages/metro-runtime/src/modules/types.flow.js +++ b/packages/metro-runtime/src/modules/types.flow.js @@ -83,6 +83,7 @@ export type HmrClientMessage = | 'debug', +data: Array, +mode: 'BRIDGE' | 'NOBRIDGE', + +platform: string, } | { +type: 'log-opt-in', diff --git a/packages/metro/src/HmrServer.js b/packages/metro/src/HmrServer.js index 6c7d7c1b4..690efe10a 100644 --- a/packages/metro/src/HmrServer.js +++ b/packages/metro/src/HmrServer.js @@ -234,6 +234,7 @@ class HmrServer { level: data.level, data: data.data, mode: data.mode, + platform: data.platform, }); } break; diff --git a/packages/metro/src/lib/TerminalReporter.js b/packages/metro/src/lib/TerminalReporter.js index 497233fc3..a58a00450 100644 --- a/packages/metro/src/lib/TerminalReporter.js +++ b/packages/metro/src/lib/TerminalReporter.js @@ -272,7 +272,13 @@ class TerminalReporter { this._logHmrClientError(event.error); break; case 'client_log': - logToConsole(this.terminal, event.level, event.mode, ...event.data); + logToConsole( + this.terminal, + event.level, + event.mode, + event.platform, + ...event.data, + ); break; case 'dep_graph_loading': const color = event.hasReducedPerformance ? chalk.red : chalk.blue; diff --git a/packages/metro/src/lib/logToConsole.js b/packages/metro/src/lib/logToConsole.js index fe37e47cf..1cd1abbd2 100644 --- a/packages/metro/src/lib/logToConsole.js +++ b/packages/metro/src/lib/logToConsole.js @@ -24,6 +24,7 @@ module.exports = ( terminal: Terminal, level: string, mode: 'BRIDGE' | 'NOBRIDGE', + platform: ?string, ...data: Array ) => { const logFunction = console[level] && level !== 'trace' ? level : 'log'; @@ -65,10 +66,15 @@ module.exports = ( data[data.length - 1] = lastItem.trimEnd(); } + const platformPrefix = + platform != null + ? chalk.inverse.bold.white` ${platform.toUpperCase()} ` + ' ' + : ''; const modePrefix = !mode || mode == 'BRIDGE' ? '' : `(${mode.toUpperCase()}) `; terminal.log( - color.bold(` ${modePrefix}${logFunction.toUpperCase()} `) + + platformPrefix + + color.bold(` ${modePrefix}${logFunction.toUpperCase()} `) + ''.padEnd(groupStack.length * 2, ' '), // `util.format` actually accepts any arguments. // If the first argument is a string, it tries to format it. diff --git a/packages/metro/src/lib/reporting.js b/packages/metro/src/lib/reporting.js index f2432992d..8cb8b6eea 100644 --- a/packages/metro/src/lib/reporting.js +++ b/packages/metro/src/lib/reporting.js @@ -117,6 +117,7 @@ export type ReportableEvent = } | { type: 'client_log', + platform: string, level: | 'trace' | 'info'