Updates from Wed 18 Mar

- [ReactNative] Add AsyncStorageTest | Spencer Ahrens
- [ReactNative] Add timers integration test | Spencer Ahrens
- [ReactNative] Remove ExpandingText | Tadeu Zagallo
- [TouchableHighlight] Preserve underlay style when restoring inactive props | Christopher Chedeau
- clean flow errors in react-native-github | Basil Hosmer
- [ReactNative] Sort React Native exports into two groups, Components and APIs | Christopher Chedeau
- [ReactNative] Rename Slider to SliderIOS | Tadeu Zagallo
- [react_native] JS files from D1919491: Improve JS logging | Martin Kosiba
- [ReactNative] Add TimerExample | Spencer Ahrens
- [RFC][ReactNative] increase timer resolution | Spencer Ahrens
- [ReactNative] Strip prefixes from NativeModules keys | Spencer Ahrens
- [ReactNative] Small docs cleanup in ActivityIndicatorIOS and DatePickerIOS | Christopher Chedeau
- [ReactNative] Improvements on perf measurement output | Jing Chen
- [ReactNative] Clean up Touchable PropTypes | Christopher Chedeau
- [ReactKit] Fail tests when redbox shows up | Alex Kotliarskyi
This commit is contained in:
Christopher Chedeau 2015-03-18 15:57:49 -07:00
parent a689113fb4
commit e3025bb624
1 changed files with 36 additions and 26 deletions

View File

@ -25,6 +25,13 @@
'use strict'; 'use strict';
var OBJECT_COLUMN_NAME = '(index)'; var OBJECT_COLUMN_NAME = '(index)';
var LOG_LEVELS = {
trace: 0,
log: 1,
info: 2,
warn: 3,
error: 4
};
function setupConsole(global) { function setupConsole(global) {
@ -32,29 +39,31 @@
return; return;
} }
function doNativeLog() { function getNativeLogFunction(level) {
var str = Array.prototype.map.call(arguments, function(arg) { return function() {
if (arg == null) { var str = Array.prototype.map.call(arguments, function(arg) {
return arg === null ? 'null' : 'undefined'; if (arg == null) {
} else if (typeof arg === 'string') { return arg === null ? 'null' : 'undefined';
return '"' + arg + '"'; } else if (typeof arg === 'string') {
} else { return '"' + arg + '"';
// Perform a try catch, just in case the object has a circular } else {
// reference or stringify throws for some other reason. // Perform a try catch, just in case the object has a circular
try { // reference or stringify throws for some other reason.
return JSON.stringify(arg); try {
} catch (e) { return JSON.stringify(arg);
if (typeof arg.toString === 'function') { } catch (e) {
try { if (typeof arg.toString === 'function') {
return arg.toString(); try {
} catch (E) { return arg.toString();
return 'unknown'; } catch (E) {
return 'unknown';
}
} }
} }
} }
} }).join(', ');
}).join(', '); global.nativeLoggingHook(str, level);
global.nativeLoggingHook(str); };
} }
var repeat = function(element, n) { var repeat = function(element, n) {
@ -75,7 +84,7 @@
} }
} }
if (rows.length === 0) { if (rows.length === 0) {
global.nativeLoggingHook(''); global.nativeLoggingHook('', LOG_LEVELS.log);
return; return;
} }
@ -121,14 +130,15 @@
// Native logging hook adds "RCTLog >" at the front of every // Native logging hook adds "RCTLog >" at the front of every
// logged string, which would shift the header and screw up // logged string, which would shift the header and screw up
// the table // the table
global.nativeLoggingHook('\n' + table.join('\n')); global.nativeLoggingHook('\n' + table.join('\n'), LOG_LEVELS.log);
} }
global.console = { global.console = {
error: doNativeLog, error: getNativeLogFunction(LOG_LEVELS.error),
info: doNativeLog, info: getNativeLogFunction(LOG_LEVELS.info),
log: doNativeLog, log: getNativeLogFunction(LOG_LEVELS.log),
warn: doNativeLog, warn: getNativeLogFunction(LOG_LEVELS.warn),
trace: getNativeLogFunction(LOG_LEVELS.trace),
table: consoleTablePolyfill table: consoleTablePolyfill
}; };