Improve console logging to Metro

Summary:
This adds a few more methods that are forwarded to Metro, most notably `console.group`, `console.groupCollapsed` and `console.groupEnd`. When using `console.group`, node.js's `console` implementation will use indentation for log messages. `console.groupCollapsed`, for now, will simply not print anything to the console. This removes all of the Relay information that was impossible to look at in Metro before.

In the future, I'd like to consider somehow including collapsed groups in the output with a way to interact and navigate through them but for now, if people would like to debug Relay queries, they should use whatever they have been using before Metro had logs.

Reviewed By: gaearon

Differential Revision: D16108266

fbshipit-source-id: 97337d93eed0b8cb464df78b59ade1fe340b7f6f
This commit is contained in:
Christoph Nakazawa
2019-07-04 07:44:28 -07:00
committed by Facebook Github Bot
parent 1f25d3c4ce
commit 76e10c4e8b
2 changed files with 19 additions and 2 deletions
+9 -1
View File
@@ -15,7 +15,15 @@ const getDevServer = require('./getDevServer');
let ID = 0;
function logToConsole(
level: 'trace' | 'info' | 'warn' | 'log',
level:
| 'trace'
| 'info'
| 'warn'
| 'log'
| 'group'
| 'groupCollapsed'
| 'groupEnd'
| 'debug',
data: Array<mixed>,
) {
let body;
+10 -1
View File
@@ -32,7 +32,16 @@ if (__DEV__) {
if (!Platform.isTesting) {
const logToConsole = require('./Devtools/logToConsole');
['log', 'warn', 'info', 'trace'].forEach(level => {
[
'trace',
'info',
'warn',
'log',
'group',
'groupCollapsed',
'groupEnd',
'debug',
].forEach(level => {
const originalFunction = console[level];
// $FlowFixMe Overwrite console methods
console[level] = function(...args) {