Add Console agent

Summary: Adds the Console agent which we hook from our console polyfill. It captures the stack and strips the frames of the polyfill.

Reviewed By: davidaurelio

Differential Revision: D4021502

fbshipit-source-id: 49cb700a139270485b7595e85e52d50c9a620db6
This commit is contained in:
Alexander Blom 2016-11-02 12:18:15 -07:00 committed by Facebook Github Bot
parent 5af2bf17bc
commit 94929b717c
1 changed files with 16 additions and 0 deletions

View File

@ -363,6 +363,15 @@ const LOG_LEVELS = {
warn: 2, warn: 2,
error: 3 error: 3
}; };
const INSPECTOR_LEVELS = [];
INSPECTOR_LEVELS[LOG_LEVELS.trace] = 'debug';
INSPECTOR_LEVELS[LOG_LEVELS.info] = 'log';
INSPECTOR_LEVELS[LOG_LEVELS.warn] = 'warning';
INSPECTOR_LEVELS[LOG_LEVELS.error] = 'error';
// Strip the inner function in getNativeLogFunction(), if in dev also
// strip method printing to originalConsole.
const INSPECTOR_FRAMES_TO_SKIP = __DEV__ ? 2 : 1;
function setupConsole(global) { function setupConsole(global) {
if (!global.nativeLoggingHook) { if (!global.nativeLoggingHook) {
@ -387,6 +396,13 @@ function setupConsole(global) {
// (Note: Logic duplicated in ExceptionsManager.js.) // (Note: Logic duplicated in ExceptionsManager.js.)
logLevel = LOG_LEVELS.warn; logLevel = LOG_LEVELS.warn;
} }
if (global.__inspectorLog) {
global.__inspectorLog(
INSPECTOR_LEVELS[logLevel],
str,
[].slice.call(arguments),
INSPECTOR_FRAMES_TO_SKIP);
}
global.nativeLoggingHook(str, logLevel); global.nativeLoggingHook(str, logLevel);
}; };
} }