Permalink
Browse files

JRLog: switch from @try+friends to NS_DURING+friends (to ease droppin…

…g JRLog into projects that don't have -fobjc-exceptions set). Also add JRCLog[Debug|Info|Warn|Error|Fatal] macros for when isn't set. Finally wrap JRLOG_CONDITIONALLY meat in standard do{}while(0) macro armor, sigh.
  • Loading branch information...
1 parent 8e9cee7 commit bda0e30c9a4c09a1418c57c70cc50dd7fade0ba8 @rentzsch committed Jan 7, 2007
Showing with 623 additions and 37 deletions.
  1. +11 −1 JRLog.h
  2. +5 −5 JRLog.m
  3. +184 −29 Saw/Saw.xcodeproj/wolf.mode1
  4. +423 −2 Saw/Saw.xcodeproj/wolf.pbxuser
View
12 JRLog.h
@@ -31,7 +31,7 @@ BOOL IsJRLogLevelActive(id self_, JRLogLevel level_);
void JRLog(id self_, JRLogLevel level_, unsigned line_, const char *file_, const char *function_, NSString *format_, ...);
#define JRLOG_CONDITIONALLY(sender,LEVEL,format,...) \
- if(IsJRLogLevelActive(sender,LEVEL)){JRLog(sender,LEVEL,__LINE__,__FILE__,__PRETTY_FUNCTION__,(format),##__VA_ARGS__);}
+ do{if(IsJRLogLevelActive(sender,LEVEL)){JRLog(sender,LEVEL,__LINE__,__FILE__,__PRETTY_FUNCTION__,(format),##__VA_ARGS__);}}while(0)
#if JRLogOverrideNSLog
id self;
@@ -45,30 +45,40 @@ id self;
#if defined(JRLOGLEVEL_OFF) || defined(JRLOGLEVEL_FATAL) || defined(JRLOGLEVEL_ERROR) || defined(JRLOGLEVEL_WARN) || defined(JRLOGLEVEL_INFO)
#define JRLogDebug(format,...)
+ #define JRCLogDebug(format,...)
#else
#define JRLogDebug(format,...) JRLOG_CONDITIONALLY(self, JRLogLevel_Debug, format, ##__VA_ARGS__)
+ #define JRCLogDebug(format,...) JRLOG_CONDITIONALLY(nil, JRLogLevel_Debug, format, ##__VA_ARGS__)
#endif
#if defined(JRLOGLEVEL_OFF) || defined(JRLOGLEVEL_FATAL) || defined(JRLOGLEVEL_ERROR) || defined(JRLOGLEVEL_WARN)
#define JRLogInfo(format,...)
+ #define JRCLogInfo(format,...)
#else
#define JRLogInfo(format,...) JRLOG_CONDITIONALLY(self, JRLogLevel_Info, format, ##__VA_ARGS__)
+ #define JRCLogInfo(format,...) JRLOG_CONDITIONALLY(nil, JRLogLevel_Info, format, ##__VA_ARGS__)
#endif
#if defined(JRLOGLEVEL_OFF) || defined(JRLOGLEVEL_FATAL) || defined(JRLOGLEVEL_ERROR)
#define JRLogWarn(format,...)
+ #define JRCLogWarn(format,...)
#else
#define JRLogWarn(format,...) JRLOG_CONDITIONALLY(self, JRLogLevel_Warn, format, ##__VA_ARGS__)
+ #define JRCLogWarn(format,...) JRLOG_CONDITIONALLY(nil, JRLogLevel_Warn, format, ##__VA_ARGS__)
#endif
#if defined(JRLOGLEVEL_OFF) || defined(JRLOGLEVEL_FATAL)
#define JRLogError(format,...)
+ #define JRCLogError(format,...)
#else
#define JRLogError(format,...) JRLOG_CONDITIONALLY(self, JRLogLevel_Error, format, ##__VA_ARGS__)
+ #define JRCLogError(format,...) JRLOG_CONDITIONALLY(nil, JRLogLevel_Error, format, ##__VA_ARGS__)
#endif
#if defined(JRLOGLEVEL_OFF)
#define JRLogFatal(format,...)
+ #define JRCLogFatal(format,...)
#else
#define JRLogFatal(format,...) JRLOG_CONDITIONALLY(self, JRLogLevel_Fatal, format, ##__VA_ARGS__)
+ #define JCRLogFatal(format,...) JRLOG_CONDITIONALLY(nil, JRLogLevel_Fatal, format, ##__VA_ARGS__)
#endif
View
10 JRLog.m
@@ -73,7 +73,7 @@ - (void)logWithLevel:(JRLogLevel)callerLevel_
destination = [[NSConnection rootProxyForConnectionWithRegisteredName:@"JRLogDestinationDO" host:nil] retain];
}
if (destination) {
- @try {
+ NS_DURING
[destination logWithDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
[[NSBundle mainBundle] bundleIdentifier], @"bundleID",
sessionUUID, @"sessionUUID",
@@ -86,14 +86,14 @@ - (void)logWithLevel:(JRLogLevel)callerLevel_
[NSString stringWithUTF8String:function_], @"function",
message_, @"message",
nil]];
- } @catch(NSException *x) {
- if ([[x name] isEqualToString:NSObjectInaccessibleException]) {
+ NS_HANDLER
+ if ([[localException name] isEqualToString:NSObjectInaccessibleException]) {
[destination release];
destination = nil;
} else {
- @throw x;
+ [localException raise];
}
- }
+ NS_ENDHANDLER
} else {
// "MyClass.m:123: blah blah"
NSLog(@"%@:%u: %@",
Oops, something went wrong.

0 comments on commit bda0e30

Please sign in to comment.