From 76e10c4e8bc3e31eecf80b15bde29d133caaca1e Mon Sep 17 00:00:00 2001 From: Christoph Nakazawa Date: Thu, 4 Jul 2019 07:41:02 -0700 Subject: [PATCH] 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 --- Libraries/Core/Devtools/logToConsole.js | 10 +++++++++- Libraries/Core/setUpDeveloperTools.js | 11 ++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Libraries/Core/Devtools/logToConsole.js b/Libraries/Core/Devtools/logToConsole.js index 93806e76cba..19241b8400d 100644 --- a/Libraries/Core/Devtools/logToConsole.js +++ b/Libraries/Core/Devtools/logToConsole.js @@ -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, ) { let body; diff --git a/Libraries/Core/setUpDeveloperTools.js b/Libraries/Core/setUpDeveloperTools.js index 46388f4f887..aefacad0a42 100644 --- a/Libraries/Core/setUpDeveloperTools.js +++ b/Libraries/Core/setUpDeveloperTools.js @@ -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) {