Created
April 24, 2011 17:33
-
-
Save psineur/939729 to your computer and use it in GitHub Desktop.
DebugLog + TinyLog - better than NSLog
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.h | |
* DebugLog | |
* | |
* Created by Karl Kraft on 3/22/09. | |
* Copyright 2009 Karl Kraft. All rights reserved. | |
* http://www.karlkraft.com/index.php/2009/03/23/114/ | |
* | |
*/ | |
#import "Foundation/Foundation.h" | |
// Like NSLog, but without annoying TimeStamps | |
void TinyLog(NSString *format,...); | |
// Better NSLog by Karl Kraft | |
#ifdef DEBUG | |
#define DebugLog(args...) _DebugLog(__FILE__,__LINE__,__PRETTY_FUNCTION__,args); | |
#else | |
#define DebugLog(x...) | |
#endif | |
void _DebugLog(const char *file, int lineNumber, const char *funcName, NSString *format,...); | |
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 | |
* DebugLog | |
* | |
* Created by Karl Kraft on 3/22/09. | |
* Copyright 2009 Karl Kraft. All rights reserved. | |
* | |
*/ | |
#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]); | |
} | |
[body release]; | |
} | |
void TinyLog(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); | |
printf("%s",[body UTF8String]); | |
[body release]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment