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?