mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-23 04:20:21 +08:00
Added new RKLog helpers for changing the log level during the execution of a block. Very helpful for debugging. closes #387
This commit is contained in:
@@ -60,22 +60,22 @@
|
||||
The message will only be logged if the log level for the active component is equal to or higher
|
||||
than the level the message was logged at (in this case, Info).
|
||||
*/
|
||||
#define RKLogCritical(...) \
|
||||
#define RKLogCritical(...) \
|
||||
lcl_log(RKLogComponent, lcl_vCritical, @"" __VA_ARGS__)
|
||||
|
||||
#define RKLogError(...) \
|
||||
#define RKLogError(...) \
|
||||
lcl_log(RKLogComponent, lcl_vError, @"" __VA_ARGS__)
|
||||
|
||||
#define RKLogWarning(...) \
|
||||
#define RKLogWarning(...) \
|
||||
lcl_log(RKLogComponent, lcl_vWarning, @"" __VA_ARGS__)
|
||||
|
||||
#define RKLogInfo(...) \
|
||||
#define RKLogInfo(...) \
|
||||
lcl_log(RKLogComponent, lcl_vInfo, @"" __VA_ARGS__)
|
||||
|
||||
#define RKLogDebug(...) \
|
||||
#define RKLogDebug(...) \
|
||||
lcl_log(RKLogComponent, lcl_vDebug, @"" __VA_ARGS__)
|
||||
|
||||
#define RKLogTrace(...) \
|
||||
#define RKLogTrace(...) \
|
||||
lcl_log(RKLogComponent, lcl_vTrace, @"" __VA_ARGS__)
|
||||
|
||||
/**
|
||||
@@ -104,8 +104,8 @@ lcl_log(RKLogComponent, lcl_vTrace, @"" __VA_ARGS__)
|
||||
// Log only critical messages from the Object Mapping component
|
||||
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelCritical);
|
||||
*/
|
||||
#define RKLogConfigureByName(name, level) \
|
||||
RKLogInitialize(); \
|
||||
#define RKLogConfigureByName(name, level) \
|
||||
RKLogInitialize(); \
|
||||
lcl_configure_by_name(name, level);
|
||||
|
||||
/**
|
||||
@@ -113,10 +113,38 @@ lcl_configure_by_name(name, level);
|
||||
enables the end-user of RestKit to leverage RKLog() to log messages inside of
|
||||
their apps.
|
||||
*/
|
||||
#define RKLogSetAppLoggingLevel(level) \
|
||||
RKLogInitialize(); \
|
||||
#define RKLogSetAppLoggingLevel(level) \
|
||||
RKLogInitialize(); \
|
||||
lcl_configure_by_name("App", level);
|
||||
|
||||
/**
|
||||
Temporarily changes the logging level for the specified component and executes the block. Any logging
|
||||
statements executed within the body of the block against the specified component will log at the new
|
||||
logging level. After the block has executed, the logging level is restored to its previous state.
|
||||
*/
|
||||
#define RKLogToComponentWithLevelWhileExecutingBlock(_component, _level, _block) \
|
||||
do { \
|
||||
int _currentLevel = _lcl_component_level[_component]; \
|
||||
lcl_configure_by_component(_component, _level); \
|
||||
@try { \
|
||||
_block(); \
|
||||
} \
|
||||
@catch (NSException *exception) { \
|
||||
@throw; \
|
||||
} \
|
||||
@finally { \
|
||||
lcl_configure_by_component(_component, _currentLevel); \
|
||||
} \
|
||||
} while(false);
|
||||
|
||||
/**
|
||||
Temporarily changes the logging level for the configured RKLogComponent and executes the block. Any logging
|
||||
statements executed within the body of the block for the current logging component will log at the new
|
||||
logging level. After the block has finished excution, the logging level is restored to its previous state.
|
||||
*/
|
||||
#define RKLogWithLevelWhileExecutingBlock(_level, _block) \
|
||||
RKLogToComponentWithLevelWhileExecutingBlock(RKLogComponent, _level, _block)
|
||||
|
||||
/**
|
||||
Set the Default Log Level
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
//
|
||||
|
||||
#import "RKLog.h"
|
||||
#import "lcl.h"
|
||||
|
||||
static BOOL loggingInitialized = NO;
|
||||
|
||||
@@ -30,3 +31,11 @@ void RKLogInitialize(void) {
|
||||
loggingInitialized = YES;
|
||||
}
|
||||
}
|
||||
|
||||
void RKLogWithComponentAtLevelWhileExecutingBlock(_lcl_component_t component, _lcl_level_t level, void (^block)(void)) {
|
||||
// _lcl_level_narrow_t currentLevel = _lcl_component_level[(__lcl_log_symbol(_component))];
|
||||
// Get the current log level for the component
|
||||
// Set the log level to the new level
|
||||
// execute the block
|
||||
// restore the log level
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user