This is how I generate a log file on device so that every NSLog statement will be logged this file:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName =[NSString stringWithFormat:@"%@.log",[NSDate date]];
NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:fileName];
freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
Now I am integrating Cocoalumberjack framework into my iOS app:
# Set a ddLogLevel
static const DDLogLevel ddLogLevel = DDLogLevelAll;
# Add logger for > iOS 10.0 and < iOS 10.0
if (@available(iOS 10.0, *)) {
[DDLog addLogger:DDOSLogger.sharedInstance];
} else {
[DDLog addLogger:DDTTYLogger.sharedInstance];
[DDLog addLogger:DDASLLogger.sharedInstance];
}
...
# I use DDLogDebug to log a debug message...
DDLogDebug(@"%@", message);
However, now it does not log to the file any more. The device that I used for testing is an iPhone 7 with iOS 12.0. So DDOSLogger is actually added. What's the problem here?
You need to create a fileLogger instance then add it to DDLog
let fileLogger: DDFileLogger = DDFileLogger()
//Some config here
DDLog.add(fileLogger)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.