1、使用CocoaPods安装CocoaLumberjack
platform :ios, ‘11.0’
target:“ProjectName” do
pod “CocoaLumberjack”, “~>3.5.1”
end
2、全局定义DDLog日志级别,才可以编译通过
#ifdef DEBUG
static const int ddLogLevel = DDLogLevelVerbose;
#else
static const int ddLogLevel = DDLogLevelWarning;
#endif
ps:
- DDLogLevelOff 关闭Log
- DDLogLevelError 打印Error级别Log
- DDLogLevelWarning 打印Error、Warning级别Log
- DDLogLevelInfo 打印Error、Warn、Info级别Log
- DDLogLevelDebug 打印Error、Warn、Info、Debug级别Log
- DDLogLevelVerbose 打印Error、Warn、Info、Debug、Verbose级别Log
3、初始化DDLog配置
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
[DDLog addLogger:[DDTTYLogger sharedInstance]]; // TTY = Xcode console
[DDLog addLogger:[DDASLLogger sharedInstance]]; // ASL = Apple System Logs
DDFileLogger *fileLogger = [[DDFileLogger