#ifndef FILELOGGING #define FILELOGGING #ifndef DEBUG #define FLOG(args...) #else #define kLOGFILEPATH @"/path/to/log/file.log" void _FLog(const char *functionName, int lineNumber, NSString *msgFormat, ...) { va_list ap; va_start(ap, msgFormat); NSString *logFormattedMessage = [[NSString alloc] initWithFormat:msgFormat arguments:ap]; va_end(ap); NSString *logMessage = [NSString stringWithFormat:@"%s[%d] %@\n", functionName, lineNumber, logFormattedMessage]; #if !__has_feature(objc_arc) [logFormattedMessage release]; #endif if (![[NSFileManager defaultManager] fileExistsAtPath:kLOGFILEPATH]) [[NSData data] writeToFile:kLOGFILEPATH atomically:YES]; NSFileHandle *handle = [NSFileHandle fileHandleForWritingAtPath:kLOGFILEPATH]; [handle truncateFileAtOffset:[handle seekToEndOfFile]]; [handle writeData:[logMessage dataUsingEncoding:NSUTF8StringEncoding]]; [handle closeFile]; } #define FLOG(args...) _FLog(__func__, __LINE__, args); #endif // DEBUG #endif // FILELOGGING