The iOS framework that grows only as fast as its documentation
NIDebuggingTools.h
1 //
2 // Copyright 2011-2014 NimbusKit
3 //
4 // Forked from Three20 June 10, 2011 - Copyright 2009-2011 Facebook
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 //
18 
19 #import <Foundation/Foundation.h>
20 
87 #if defined(DEBUG) || defined(NI_DEBUG)
88 
95 #import <TargetConditionals.h>
96 
97 #if defined __cplusplus
98 extern "C" {
99 #endif
100 
101 int NIIsInDebugger(void);
102 
103 #if defined __cplusplus
104 }
105 #endif
106 
107 #if TARGET_IPHONE_SIMULATOR
108 // We leave the __asm__ in this macro so that when a break occurs, we don't have to step out of
109 // a "breakInDebugger" function.
110 #define NIDASSERT(xx) { if (!(xx)) { NIDPRINT(@"NIDASSERT failed: %s", #xx); \
111 if (NIDebugAssertionsShouldBreak && NIIsInDebugger()) { __asm__("int $3\n" : : ); } } \
112 } ((void)0)
113 #else
114 #define NIDASSERT(xx) { if (!(xx)) { NIDPRINT(@"NIDASSERT failed: %s", #xx); \
115 if (NIDebugAssertionsShouldBreak && NIIsInDebugger()) { raise(SIGTRAP); } } \
116 } ((void)0)
117 #endif // #if TARGET_IPHONE_SIMULATOR
118 
119 #else
120 #define NIDASSERT(xx) ((void)0)
121 #endif // #if defined(DEBUG) || defined(NI_DEBUG)
122 
123 
124 #define NILOGLEVEL_INFO 5
125 #define NILOGLEVEL_WARNING 3
126 #define NILOGLEVEL_ERROR 1
127 
135 extern NSInteger NIMaxLogLevel;
136 
145 extern BOOL NIDebugAssertionsShouldBreak;
146 
153 #if defined(DEBUG) || defined(NI_DEBUG)
154 #define NIDPRINT(xx, ...) NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
155 #else
156 #define NIDPRINT(xx, ...) ((void)0)
157 #endif // #if defined(DEBUG) || defined(NI_DEBUG)
158 
162 #define NIDPRINTMETHODNAME() NIDPRINT(@"%s", __PRETTY_FUNCTION__)
163 
164 #if defined(DEBUG) || defined(NI_DEBUG)
165 
171 #define NIDCONDITIONLOG(condition, xx, ...) { if ((condition)) { NIDPRINT(xx, ##__VA_ARGS__); } \
172 } ((void)0)
173 #else
174 #define NIDCONDITIONLOG(condition, xx, ...) ((void)0)
175 #endif // #if defined(DEBUG) || defined(NI_DEBUG)
176 
177 
181 #define NIDERROR(xx, ...) NIDCONDITIONLOG((NILOGLEVEL_ERROR <= NIMaxLogLevel), xx, ##__VA_ARGS__)
182 
186 #define NIDWARNING(xx, ...) NIDCONDITIONLOG((NILOGLEVEL_WARNING <= NIMaxLogLevel), \
187 xx, ##__VA_ARGS__)
188 
192 #define NIDINFO(xx, ...) NIDCONDITIONLOG((NILOGLEVEL_INFO <= NIMaxLogLevel), xx, ##__VA_ARGS__)
193 // End of Debugging Tools //////////////////////////////////////////////////////////////////
int NIIsInDebugger(void)
Assertions that only fire when DEBUG is defined.
NSInteger NIMaxLogLevel
The maximum log level to output for Nimbus debug logs.
BOOL NIDebugAssertionsShouldBreak
Whether or not debug assertions should halt program execution like a breakpoint when they fail...