2015-03-23 20:28:42 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-04-07 14:36:26 +00:00
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
#import "RCTAssert.h"
|
2015-04-21 12:26:51 +00:00
|
|
|
#import "RCTDefines.h"
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-04-07 14:36:26 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
#define RCTLOG_FATAL_LEVEL RCTLogLevelMustFix
|
|
|
|
#define RCTLOG_REDBOX_LEVEL RCTLogLevelError
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An enum representing the severity of the log message.
|
|
|
|
*/
|
|
|
|
typedef NS_ENUM(NSInteger, RCTLogLevel) {
|
|
|
|
RCTLogLevelInfo = 1,
|
|
|
|
RCTLogLevelWarning = 2,
|
|
|
|
RCTLogLevelError = 3,
|
|
|
|
RCTLogLevelMustFix = 4
|
|
|
|
};
|
2015-02-20 04:10:52 +00:00
|
|
|
|
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,
|
|
|
|
NSString *fileName,
|
|
|
|
NSNumber *lineNumber,
|
|
|
|
NSString *message
|
|
|
|
);
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-04-20 11:55:05 +00:00
|
|
|
/**
|
2015-04-21 12:26:51 +00:00
|
|
|
* Get a given thread's name (or the current queue, if in debug mode)
|
2015-04-20 11:55:05 +00:00
|
|
|
*/
|
2015-04-21 12:26:51 +00:00
|
|
|
RCT_EXTERN NSString *RCTThreadName(NSThread *);
|
2015-04-20 11:55:05 +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,
|
|
|
|
NSThread *thread,
|
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* These methods get and set the current logging threshold. This is the level
|
|
|
|
* 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
|
|
|
|
|
|
|
/**
|
|
|
|
* These methods get and set the current logging function called by the RCTLogXX
|
|
|
|
* 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
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
|
|
|
/**
|
|
|
|
* Private logging functions - ignore these.
|
|
|
|
*/
|
2015-04-21 12:26:51 +00:00
|
|
|
RCT_EXTERN void _RCTLogFormat(RCTLogLevel, const char *, int, NSString *, ...) NS_FORMAT_FUNCTION(4,5);
|
2015-04-07 14:36:26 +00:00
|
|
|
#define _RCTLog(lvl, ...) do { \
|
2015-04-11 22:08:00 +00:00
|
|
|
if (lvl >= RCTLOG_FATAL_LEVEL) { RCTAssert(NO, __VA_ARGS__); } \
|
2015-04-07 14:36:26 +00:00
|
|
|
_RCTLogFormat(lvl, __FILE__, __LINE__, __VA_ARGS__); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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__)
|