2015-03-23 20:28:42 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2015-03-23 20:28:42 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-03-23 20:28:42 +00:00
|
|
|
*/
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-04-07 14:36:26 +00:00
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
2016-11-23 15:47:52 +00:00
|
|
|
#import <React/RCTAssert.h>
|
|
|
|
#import <React/RCTDefines.h>
|
2017-04-01 10:16:52 +00:00
|
|
|
#import <React/RCTUtils.h>
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-10-13 14:30:11 +00:00
|
|
|
#ifndef RCTLOG_ENABLED
|
|
|
|
#define RCTLOG_ENABLED 1
|
|
|
|
#endif
|
|
|
|
|
2015-04-07 14:36:26 +00:00
|
|
|
/**
|
2015-11-05 20:19:56 +00:00
|
|
|
* Thresholds for logs to display a redbox. You can override these values when debugging
|
|
|
|
* in order to tweak the default logging behavior.
|
2015-04-07 14:36:26 +00:00
|
|
|
*/
|
2015-10-13 14:30:11 +00:00
|
|
|
#ifndef RCTLOG_REDBOX_LEVEL
|
2015-04-07 14:36:26 +00:00
|
|
|
#define RCTLOG_REDBOX_LEVEL RCTLogLevelError
|
2015-10-13 14:30:11 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logging macros. Use these to log information, warnings and errors in your
|
|
|
|
* own code.
|
|
|
|
*/
|
|
|
|
#define RCTLog(...) _RCTLog(RCTLogLevelInfo, __VA_ARGS__)
|
2015-11-05 20:20:08 +00:00
|
|
|
#define RCTLogTrace(...) _RCTLog(RCTLogLevelTrace, __VA_ARGS__)
|
2015-10-13 14:30:11 +00:00
|
|
|
#define RCTLogInfo(...) _RCTLog(RCTLogLevelInfo, __VA_ARGS__)
|
2017-01-25 20:16:25 +00:00
|
|
|
#define RCTLogAdvice(string, ...) RCTLogWarn([@"(ADVICE) " stringByAppendingString:(NSString *)string], __VA_ARGS__)
|
2015-10-13 14:30:11 +00:00
|
|
|
#define RCTLogWarn(...) _RCTLog(RCTLogLevelWarning, __VA_ARGS__)
|
|
|
|
#define RCTLogError(...) _RCTLog(RCTLogLevelError, __VA_ARGS__)
|
2015-04-07 14:36:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An enum representing the severity of the log message.
|
|
|
|
*/
|
|
|
|
typedef NS_ENUM(NSInteger, RCTLogLevel) {
|
2015-11-05 20:20:08 +00:00
|
|
|
RCTLogLevelTrace = 0,
|
2015-04-07 14:36:26 +00:00
|
|
|
RCTLogLevelInfo = 1,
|
|
|
|
RCTLogLevelWarning = 2,
|
|
|
|
RCTLogLevelError = 3,
|
2015-11-05 20:19:56 +00:00
|
|
|
RCTLogLevelFatal = 4
|
2015-04-07 14:36:26 +00:00
|
|
|
};
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-11-11 14:42:27 +00:00
|
|
|
/**
|
|
|
|
* An enum representing the source of a log message.
|
|
|
|
*/
|
|
|
|
typedef NS_ENUM(NSInteger, RCTLogSource) {
|
|
|
|
RCTLogSourceNative = 1,
|
|
|
|
RCTLogSourceJavaScript = 2
|
|
|
|
};
|
|
|
|
|
2015-04-07 14:36:26 +00:00
|
|
|
/**
|
|
|
|
* A block signature to be used for custom logging functions. In most cases you
|
|
|
|
* will want to pass these arguments to the RCTFormatLog function in order to
|
2015-04-08 12:42:43 +00:00
|
|
|
* generate a string.
|
2015-04-07 14:36:26 +00:00
|
|
|
*/
|
|
|
|
typedef void (^RCTLogFunction)(
|
|
|
|
RCTLogLevel level,
|
2015-11-11 14:42:27 +00:00
|
|
|
RCTLogSource source,
|
2015-04-07 14:36:26 +00:00
|
|
|
NSString *fileName,
|
|
|
|
NSNumber *lineNumber,
|
|
|
|
NSString *message
|
|
|
|
);
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-04-07 14:36:26 +00:00
|
|
|
/**
|
|
|
|
* A method to generate a string from a collection of log data. To omit any
|
|
|
|
* particular data from the log, just pass nil or zero for the argument.
|
|
|
|
*/
|
2015-04-21 16:48:29 +00:00
|
|
|
RCT_EXTERN NSString *RCTFormatLog(
|
2015-04-07 14:36:26 +00:00
|
|
|
NSDate *timestamp,
|
|
|
|
RCTLogLevel level,
|
|
|
|
NSString *fileName,
|
|
|
|
NSNumber *lineNumber,
|
|
|
|
NSString *message
|
|
|
|
);
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-04-07 14:36:26 +00:00
|
|
|
/**
|
|
|
|
* The default logging function used by RCTLogXX.
|
|
|
|
*/
|
|
|
|
extern RCTLogFunction RCTDefaultLogFunction;
|
|
|
|
|
|
|
|
/**
|
2015-07-29 12:54:59 +00:00
|
|
|
* These methods get and set the global logging threshold. This is the level
|
2015-04-07 14:36:26 +00:00
|
|
|
* below which logs will be ignored. Default is RCTLogLevelInfo for debug and
|
|
|
|
* RCTLogLevelError for production.
|
|
|
|
*/
|
2015-04-21 12:26:51 +00:00
|
|
|
RCT_EXTERN void RCTSetLogThreshold(RCTLogLevel threshold);
|
|
|
|
RCT_EXTERN RCTLogLevel RCTGetLogThreshold(void);
|
2015-04-07 14:36:26 +00:00
|
|
|
|
|
|
|
/**
|
2015-07-29 12:54:59 +00:00
|
|
|
* These methods get and set the global logging function called by the RCTLogXX
|
2015-04-07 14:36:26 +00:00
|
|
|
* macros. You can use these to replace the standard behavior with custom log
|
|
|
|
* functionality.
|
|
|
|
*/
|
2015-04-21 12:26:51 +00:00
|
|
|
RCT_EXTERN void RCTSetLogFunction(RCTLogFunction logFunction);
|
|
|
|
RCT_EXTERN RCTLogFunction RCTGetLogFunction(void);
|
2015-04-07 14:36:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This appends additional code to the existing log function, without replacing
|
|
|
|
* the existing functionality. Useful if you just want to forward logs to an
|
|
|
|
* extra service without changing the default behavior.
|
|
|
|
*/
|
2015-04-21 12:26:51 +00:00
|
|
|
RCT_EXTERN void RCTAddLogFunction(RCTLogFunction logFunction);
|
2015-04-07 14:36:26 +00:00
|
|
|
|
2015-07-29 12:54:59 +00:00
|
|
|
/**
|
|
|
|
* This method temporarily overrides the log function while performing the
|
|
|
|
* specified block. This is useful for testing purposes (to detect if a given
|
|
|
|
* function logs something) or to suppress or override logging temporarily.
|
|
|
|
*/
|
|
|
|
RCT_EXTERN void RCTPerformBlockWithLogFunction(void (^block)(void), RCTLogFunction logFunction);
|
|
|
|
|
2015-04-07 14:36:26 +00:00
|
|
|
/**
|
|
|
|
* This method adds a conditional prefix to any messages logged within the scope
|
|
|
|
* of the passed block. This is useful for adding additional context to log
|
|
|
|
* messages. The block will be performed synchronously on the current thread.
|
|
|
|
*/
|
2015-04-21 12:26:51 +00:00
|
|
|
RCT_EXTERN void RCTPerformBlockWithLogPrefix(void (^block)(void), NSString *prefix);
|
2015-04-07 14:36:26 +00:00
|
|
|
|
|
|
|
/**
|
2015-06-15 14:53:45 +00:00
|
|
|
* Private logging function - ignore this.
|
2015-04-07 14:36:26 +00:00
|
|
|
*/
|
2015-10-13 14:30:11 +00:00
|
|
|
#if RCTLOG_ENABLED
|
2016-11-16 15:28:01 +00:00
|
|
|
#define _RCTLog(lvl, ...) _RCTLogNativeInternal(lvl, __FILE__, __LINE__, __VA_ARGS__)
|
2015-10-13 14:30:11 +00:00
|
|
|
#else
|
|
|
|
#define _RCTLog(lvl, ...) do { } while (0)
|
|
|
|
#endif
|
2015-04-07 14:36:26 +00:00
|
|
|
|
2015-11-11 14:42:27 +00:00
|
|
|
RCT_EXTERN void _RCTLogNativeInternal(RCTLogLevel, const char *, int, NSString *, ...) NS_FORMAT_FUNCTION(4,5);
|
|
|
|
RCT_EXTERN void _RCTLogJavaScriptInternal(RCTLogLevel, NSString *);
|