这就是我在设备上生成日志文件的方式,以便每个 NSLog 语句都将记录在此文件中:
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);
现在我将 Cocoalumberjack 框架集成到我的 iOS 应用程序中:
# 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);
但是,现在它不再记录到文件中。我用于测试的设备是带有 iOS 12.0 的 iPhone 7。所以实际上添加了 DDOSLogger。这里有什么问题?