Skip to content

Commit

Permalink
Added DLog function for better debug logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronpk committed Sep 5, 2011
1 parent 583f8e7 commit a6a31c8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
20 changes: 20 additions & 0 deletions DebugLog.h
@@ -0,0 +1,20 @@
/*
* DebugLog.h
* DebugLog
*
* Created by Karl Kraft on 3/22/09.
* Copyright 2009 Karl Kraft. All rights reserved.
*
*/

#ifdef DEBUG

#define DLog(args...) _DebugLog(__FILE__,__LINE__,__PRETTY_FUNCTION__,args);

#else

#define DLog(x...)

#endif

void _DebugLog(const char *file, int lineNumber, const char *funcName, NSString *format,...);
30 changes: 30 additions & 0 deletions DebugLog.m
@@ -0,0 +1,30 @@
/*
* 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) \n\t\t%s",threadName,funcName,[fileName UTF8String],lineNumber,[body UTF8String]);
} else {
fprintf(stderr,"%p/%s (%s:%d) \n\t\t%s",[NSThread currentThread],funcName,[fileName UTF8String],lineNumber,[body UTF8String]);
}
[body release];
}

2 changes: 2 additions & 0 deletions MapAttack_Prefix.pch
Expand Up @@ -5,4 +5,6 @@
#ifdef __OBJC__ #ifdef __OBJC__
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "DebugLog.h"
#endif #endif

0 comments on commit a6a31c8

Please sign in to comment.