added RCTLog.logToConsole() to force log regardless of debugger connection
Summary: This adds an alternative logging method that can be called from native side. `logIfNoLoggingHook()` will pass the message to console only if there's Chrome debugger attached. This new method sends the message to console regardless to notify the developers better. Reviewed By: yungsters Differential Revision: D4669663 fbshipit-source-id: 3940816dadd08d450f066b7223f6d26a38a70921
This commit is contained in:
parent
7eded2d8ed
commit
1a8d216458
|
@ -11,11 +11,11 @@
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var BatchedBridge = require('BatchedBridge');
|
const BatchedBridge = require('BatchedBridge');
|
||||||
|
|
||||||
var invariant = require('fbjs/lib/invariant');
|
const invariant = require('fbjs/lib/invariant');
|
||||||
|
|
||||||
var levelsMap = {
|
const levelsMap = {
|
||||||
log: 'log',
|
log: 'log',
|
||||||
info: 'info',
|
info: 'info',
|
||||||
warn: 'warn',
|
warn: 'warn',
|
||||||
|
@ -25,18 +25,24 @@ var levelsMap = {
|
||||||
|
|
||||||
class RCTLog {
|
class RCTLog {
|
||||||
// level one of log, info, warn, error, mustfix
|
// level one of log, info, warn, error, mustfix
|
||||||
static logIfNoNativeHook() {
|
static logIfNoNativeHook(...args) {
|
||||||
var args = Array.prototype.slice.call(arguments);
|
if (typeof global.nativeLoggingHook === 'undefined') {
|
||||||
var level = args.shift();
|
// We already printed in xcode, so only log here if using a js debugger
|
||||||
var logFn = levelsMap[level];
|
RCTLog.logToConsole(...args);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log to console regardless of nativeLoggingHook
|
||||||
|
static logToConsole(level, ...args) {
|
||||||
|
const logFn = levelsMap[level];
|
||||||
invariant(
|
invariant(
|
||||||
logFn,
|
logFn,
|
||||||
'Level "' + level + '" not one of ' + Object.keys(levelsMap)
|
'Level "' + level + '" not one of ' + Object.keys(levelsMap)
|
||||||
);
|
);
|
||||||
if (typeof global.nativeLoggingHook === 'undefined') {
|
|
||||||
// We already printed in xcode, so only log here if using a js debugger
|
console[logFn](...args);
|
||||||
console[logFn].apply(console, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue