Permalink
Browse files

Added DLog function for better debug logging.

  • Loading branch information...
aaronpk committed Sep 5, 2011
1 parent 583f8e7 commit a6a31c85b16d9de4bed001f4d1d8cf237d89c6fd
Showing with 52 additions and 0 deletions.
  1. +20 −0 DebugLog.h
  2. +30 −0 DebugLog.m
  3. +2 −0 MapAttack_Prefix.pch
View
@@ -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,...);
View
@@ -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];
+}
+
View
@@ -5,4 +5,6 @@
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
+ #import "DebugLog.h"
#endif
+

0 comments on commit a6a31c8

Please sign in to comment.