Skip to content

Instantly share code, notes, and snippets.

@chrissearle
Created August 12, 2011 19:19
Show Gist options
  • Save chrissearle/1142764 to your computer and use it in GitHub Desktop.
Save chrissearle/1142764 to your computer and use it in GitHub Desktop.
AppLog for NSLog
Taken from iOS recipes and renamed to something I find easier to type ;)
This all works fine. When -DAPPDEBUG=1 is not defined nothing gets logged.
When defined AppLog works like NSLog.
But - when defined - I get a "Semantic issue: Implicit declaration of function 'AppDebugLog' is invalid in C99" every place I use AppLog as an XCode warning.
Should I ignore? Have I imported the header in the wrong place?
#ifdef APPDEBUG
#define AppLog(format...) AppDebugLog(__FILE__, __LINE__, format)
#else
#define AppLog(format...)
#endif
void AppDebugLog(const char *fileName, int lineNumber, NSString *fmt, ...) {
va_list args;
va_start(args, fmt);
static NSDateFormatter *debugFormatter = nil;
if (debugFormatter == nil) {
debugFormatter = [[NSDateFormatter alloc] init];
[debugFormatter setDateFormat:@"yyyyMMdd.HH:mm:ss"];
}
NSString *msg = [[NSString alloc] initWithFormat:fmt arguments:args];
NSString *filePath = [[NSString alloc] initWithUTF8String:fileName];
NSString *timestamp = [debugFormatter stringFromDate:[NSDate date]];
NSDictionary *info = [[NSBundle mainBundle] infoDictionary];
NSString *appName = [info objectForKey:(NSString *)kCFBundleNameKey];
fprintf(stdout, "%s %s[%s:%d] %s\n",
[timestamp UTF8String],
[appName UTF8String],
[[filePath lastPathComponent] UTF8String],
lineNumber,
[msg UTF8String]);
va_end(args);
[msg release];
[filePath release];
}
//
// Prefix header for all source files of the 'incogito' target in the 'incogito' project
//
#import <Availability.h>
#ifndef __IPHONE_4_0
#warning "This project uses features only available in iPhone SDK 4.0 and later."
#endif
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#endif
#import "AppLog.h"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment