Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add platform tag for logs #1203

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/metro-runtime/src/modules/types.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export type HmrClientMessage =
| 'debug',
+data: Array<mixed>,
+mode: 'BRIDGE' | 'NOBRIDGE',
+platform: string,
}
| {
+type: 'log-opt-in',
Expand Down
1 change: 1 addition & 0 deletions packages/metro/src/HmrServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ class HmrServer<TClient: Client> {
level: data.level,
data: data.data,
mode: data.mode,
platform: data.platform,
});
}
break;
Expand Down
8 changes: 7 additions & 1 deletion packages/metro/src/lib/TerminalReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion packages/metro/src/lib/logToConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = (
terminal: Terminal,
level: string,
mode: 'BRIDGE' | 'NOBRIDGE',
platform: ?string,
...data: Array<mixed>
) => {
const logFunction = console[level] && level !== 'trace' ? level : 'log';
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions packages/metro/src/lib/reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export type ReportableEvent =
}
| {
type: 'client_log',
platform: string,
level:
| 'trace'
| 'info'
Expand Down