这是我在设备上生成日志文件的方式,以便每个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。这是什么问题?
答案 0 :(得分:0)
您需要创建一个fileLogger实例,然后将其添加到DDLog
let fileLogger: DDFileLogger = DDFileLogger()
//Some config here
DDLog.add(fileLogger)