forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReactClientConsoleConfigBrowser.js
76 lines (71 loc) · 1.89 KB
/
ReactClientConsoleConfigBrowser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import {warn, error} from 'shared/consoleWithStackDev';
const badgeFormat = '%c%s%c ';
// Same badge styling as DevTools.
const badgeStyle =
// We use a fixed background if light-dark is not supported, otherwise
// we use a transparent background.
'background: #e6e6e6;' +
'background: light-dark(rgba(0,0,0,0.1), rgba(255,255,255,0.25));' +
'color: #000000;' +
'color: light-dark(#000000, #ffffff);' +
'border-radius: 2px';
const resetStyle = '';
const pad = ' ';
export function printToConsole(
methodName: string,
args: Array<any>,
badgeName: string,
): void {
let offset = 0;
switch (methodName) {
case 'dir':
case 'dirxml':
case 'groupEnd':
case 'table': {
// These methods cannot be colorized because they don't take a formatting string.
// eslint-disable-next-line react-internal/no-production-logging
console[methodName].apply(console, args);
return;
}
case 'assert': {
// assert takes formatting options as the second argument.
offset = 1;
}
}
const newArgs = args.slice(0);
if (typeof newArgs[offset] === 'string') {
newArgs.splice(
offset,
1,
badgeFormat + newArgs[offset],
badgeStyle,
pad + badgeName + pad,
resetStyle,
);
} else {
newArgs.splice(
offset,
0,
badgeFormat,
badgeStyle,
pad + badgeName + pad,
resetStyle,
);
}
if (methodName === 'error') {
error.apply(console, newArgs);
} else if (methodName === 'warn') {
warn.apply(console, newArgs);
} else {
// $FlowFixMe[invalid-computed-prop]
console[methodName].apply(console, newArgs); // eslint-disable-line react-internal/no-production-logging
}
}