Disable RCTLog completely in production

Reviewed By: @nicklockwood

Differential Revision: D2521718

fb-gh-sync-id: f06c9af3906ae8cebca0d318fc2b0e2d03671220
This commit is contained in:
Pieter De Baets 2015-10-13 07:30:11 -07:00 committed by facebook-github-bot-4
parent c70cbbaf61
commit 44c651037a
2 changed files with 26 additions and 12 deletions

View File

@ -12,13 +12,32 @@
#import "RCTAssert.h"
#import "RCTDefines.h"
#ifndef RCTLOG_ENABLED
#define RCTLOG_ENABLED 1
#endif
/**
* Thresholds for logs to raise an assertion, or display redbox, respectively.
* You can override these values when debugging in order to tweak the default
* logging behavior.
*/
#ifndef RCTLOG_FATAL_LEVEL
#define RCTLOG_FATAL_LEVEL RCTLogLevelMustFix
#endif
#ifndef RCTLOG_REDBOX_LEVEL
#define RCTLOG_REDBOX_LEVEL RCTLogLevelError
#endif
/**
* Logging macros. Use these to log information, warnings and errors in your
* own code.
*/
#define RCTLog(...) _RCTLog(RCTLogLevelInfo, __VA_ARGS__)
#define RCTLogInfo(...) _RCTLog(RCTLogLevelInfo, __VA_ARGS__)
#define RCTLogWarn(...) _RCTLog(RCTLogLevelWarning, __VA_ARGS__)
#define RCTLogError(...) _RCTLog(RCTLogLevelError, __VA_ARGS__)
#define RCTLogMustFix(...) _RCTLog(RCTLogLevelMustFix, __VA_ARGS__)
/**
* An enum representing the severity of the log message.
@ -99,17 +118,12 @@ RCT_EXTERN void RCTPerformBlockWithLogPrefix(void (^block)(void), NSString *pref
/**
* Private logging function - ignore this.
*/
#if RCTLOG_ENABLED
#define _RCTLog(lvl, ...) do { \
if (lvl >= RCTLOG_FATAL_LEVEL) { RCTAssert(NO, __VA_ARGS__); } \
_RCTLogFormat(lvl, __FILE__, __LINE__, __VA_ARGS__); } while (0)
RCT_EXTERN void _RCTLogFormat(RCTLogLevel, const char *, int, NSString *, ...) NS_FORMAT_FUNCTION(4,5);
_RCTLogInternal(lvl, __FILE__, __LINE__, __VA_ARGS__); } while (0)
#else
#define _RCTLog(lvl, ...) do { } while (0)
#endif
/**
* Logging macros. Use these to log information, warnings and errors in your
* own code.
*/
#define RCTLog(...) _RCTLog(RCTLogLevelInfo, __VA_ARGS__)
#define RCTLogInfo(...) _RCTLog(RCTLogLevelInfo, __VA_ARGS__)
#define RCTLogWarn(...) _RCTLog(RCTLogLevelWarning, __VA_ARGS__)
#define RCTLogError(...) _RCTLog(RCTLogLevelError, __VA_ARGS__)
#define RCTLogMustFix(...) _RCTLog(RCTLogLevelMustFix, __VA_ARGS__)
RCT_EXTERN void _RCTLogInternal(RCTLogLevel, const char *, int, NSString *, ...) NS_FORMAT_FUNCTION(4,5);

View File

@ -190,7 +190,7 @@ NSString *RCTFormatLog(
return log;
}
void _RCTLogFormat(
void _RCTLogInternal(
RCTLogLevel level,
const char *fileName,
int lineNumber,