-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathPO2Log.mm
33 lines (32 loc) · 902 Bytes
/
PO2Log.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#import "PO2Log.h"
bool PO2Log(NSString *string, bool enabled) {
if (enabled) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"%@", string);
NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:PO2LogPath];
if (!fileHandle) {
[[NSFileManager defaultManager] createFileAtPath:PO2LogPath contents:nil attributes:nil];
fileHandle = [NSFileHandle fileHandleForWritingAtPath:PO2LogPath];
}
if (fileHandle) {
if (![string hasSuffix:@"\n"]) {
string = [string stringByAppendingString:@"\n"];
}
@try {
[fileHandle seekToEndOfFile];
[fileHandle writeData:[string dataUsingEncoding:NSUTF8StringEncoding]];
}
@catch (NSException *e) {
NSLog(@"Failed to log to file! ━Σ(゚Д゚|||)━ %@", e);
return 0;
}
[fileHandle closeFile];
return 1;
} else {
return 0;
}
[pool drain];
} else {
return 0;
}
}