-
-
Save CreatureSurvive/dc07c4d191a2d503f626554f12ed0da1 to your computer and use it in GitHub Desktop.
Log to a custom file, can be used to get logs from users with a debug build.
This file contains 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
#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]; | |
[logFormattedMessage release]; | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment