Last active
December 27, 2015 19:39
-
-
Save JRG-Developer/7377982 to your computer and use it in GitHub Desktop.
DebugLog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example Usage | |
- (void)exampleMethod | |
{ | |
DebugMethod(self, _cmd); // _cmd refers to the selector for the method you're in | |
DebugLog(@"This message will only be logged on DEBUG"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* DebugLog.m | |
* | |
* Created by Karl Kraft on 3/22/09. | |
* http://www.karlkraft.com | |
* | |
* "DebugMethod" added by Joshua Greene ([email protected]) | |
* | |
*/ | |
#ifdef DEBUG | |
#define DebugLog(args...) _DebugLog(__FILE__,__LINE__,__PRETTY_FUNCTION__,args) | |
#define DebugMethod(class, selector) _DebugMethod(class, selector) | |
#else | |
#define DebugLog(x...) | |
#define DebugMethod(x...) | |
#endif | |
void _DebugLog(const char *file, int lineNumber, const char *funcName, NSString *format,...); | |
void _DebugMethod(NSObject *object, SEL selector); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* DebugLog.m | |
* | |
* Created by Karl Kraft on 3/22/09. | |
* http://www.karlkraft.com | |
* | |
* "DebugMethod" added by Joshua Greene ([email protected]) | |
* | |
*/ | |
#include "DebugLog.h" | |
void _DebugLog(const char *file, int lineNumber, const char *funcName, NSString *format,...) { | |
va_list ap; | |
va_start (ap, format); | |
if (![format hasSuffix: @"\n"]) { | |
format = [format stringByAppendingString: @"\n"]; | |
} | |
NSString *body = [[NSString alloc] initWithFormat: format arguments: ap]; | |
va_end (ap); | |
const char *threadName = [[[NSThread currentThread] name] UTF8String]; | |
NSString *fileName=[[NSString stringWithUTF8String:file] lastPathComponent]; | |
if (threadName) { | |
fprintf(stderr,"%s/%s (%s:%d) %s",threadName,funcName,[fileName UTF8String],lineNumber,[body UTF8String]); | |
} else { | |
fprintf(stderr,"%p/%s (%s:%d) %s",[NSThread currentThread],funcName,[fileName UTF8String],lineNumber,[body UTF8String]); | |
} | |
} | |
void _DebugMethod(NSObject *object, SEL selector) { | |
DebugLog(@"Running %@ '%@'", object, NSStringFromSelector(selector)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment