04 | //
Created by Tom Fewster on 08/06/2010. |
07 | #if
TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR |
08 | #
import <UIKit/UIKit.h> |
10 | #
import <Cocoa/Cocoa.h> |
14 | #
define DebugLog(format, ...) NSLog(@"<Debug>: " format @" [" __FILE__ @":%i]", ##__VA_ARGS__, __LINE__) |
16 | #
define DebugTrace(format, ...) NSLog(@"<Trace>: " format @" [" __FILE__ @":%i]", ##__VA_ARGS__, __LINE__) |
18 | #
define DebugTrace(format, ...) |
20 | #
define InfoLog(format, ...) NSLog(@"<Info> " format @" [" __FILE__ @":%i]", ##__VA_ARGS__, __LINE__) |
21 | #
define WarningLog(format, ...) NSLog(@"<Warning> " format @" [" __FILE__ @":%i]", ##__VA_ARGS__, __LINE__) |
22 | #
define ErrorLog(format, ...) NSLog(@"<Error> " format @" [" __FILE__ @":%i]", ##__VA_ARGS__, __LINE__) |
24 | #
define DebugLog(format, ...) |
25 | #
define DebugTrace(format, ...) |
26 | #
define InfoLog(format, ...) NSLog(@"<Info>: " format, ##__VA_ARGS__) |
27 | #
define WarningLog(format, ...) NSLog(@"<Warning>: " format, ##__VA_ARGS__) |
28 | #
define ErrorLog(format, ...) NSLog(@"<Error>: " format, ##__VA_ARGS__) |
31 | void
initialiseLogger(void); |
view
source
04 | //
Created by Tom Fewster on 06/04/2012. |
12 | #include
<sys/sysctl.h> |
14 | void
initialiseLogger(void) { |
18 | struct
kinfo_proc info; |
21 | //
Initialize the flags so that, if sysctl fails for some bizarre |
22 | //
reason, we get a predictable result. |
24 | info.kp_proc.p_flag
= 0; |
26 | //
Initialize mib, which tells sysctl the info we want, in this case |
27 | //
we're looking for information about a specific process ID. |
31 | mib[2]
= KERN_PROC_PID; |
37 | junk
= sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0); |
40 | //
We're being debugged if the P_TRACED flag is set. |
41 | //
so, if we are being debugged the out put will go to Xcode's console |
42 | //
other wise redirect it to a file in our documents directory |
43 | if
(!((info.kp_proc.p_flag & P_TRACED) != 0)) { |
44 | //
find our applications documents directory |
45 | NSArray
*paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); |
46 | NSString
*documentsDirectory = [paths objectAtIndex:0]; |
48 | //
create a unique files name keyed off the date |
49 | NSDateFormatter
*dateFormatter = [[NSDateFormatter alloc] init]; |
50 | [dateFormatter
setDateFormat:@"yyyyMMddHHmmss"]; |
51 | NSString
*fileName = [NSString stringWithFormat:@"%@.log", [dateFormatter stringFromDate:[NSDate date]]]; |
52 | NSString
*logFilePath = [documentsDirectory stringByAppendingPathComponent:fileName]; |
54 | //
redirect stderr to our new file |
55 | freopen([logFilePath
cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr); |
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理