mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
76e10c4e8b
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
49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @flow strict-local
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const getDevServer = require('./getDevServer');
|
|
|
|
let ID = 0;
|
|
|
|
function logToConsole(
|
|
level:
|
|
| 'trace'
|
|
| 'info'
|
|
| 'warn'
|
|
| 'log'
|
|
| 'group'
|
|
| 'groupCollapsed'
|
|
| 'groupEnd'
|
|
| 'debug',
|
|
data: Array<mixed>,
|
|
) {
|
|
let body;
|
|
try {
|
|
body = JSON.stringify({id: ID++, level, data});
|
|
} catch (error) {
|
|
body = JSON.stringify({id: ID++, level, data: [error.message]});
|
|
}
|
|
fetch(getDevServer().url + 'log-to-console', {
|
|
method: 'POST',
|
|
body,
|
|
}).catch(e => {
|
|
// ...Oh well!
|
|
// If metro is running, logs should be sent to metro.
|
|
// If metro is NOT running, this will throw an exception every time... and
|
|
// those exceptions will be caught and logged, which will throw another
|
|
// exception, etc, causing infinite exception loop which affects UI perf.
|
|
// If we swallow silently here, that won't happen.
|
|
});
|
|
}
|
|
|
|
module.exports = logToConsole;
|