也许看了上面的简单介绍,不知道如何去设置打印的级别,其实很简单,我的做法是构造一个头文件,因为我们会在很多的文件中用到这个级别设定,所以我们单独列出来,那个文件用只需要去引用头文件即可
在头文件中写入如下代码
#import "DDLog.h"
#import "DDTTYLogger.h"
#import "DDASLLogger.h"
#import "DDFileLogger.h"
#if DEBUG
static const int ddLogLevel = LOG_LEVEL_VERBOSE;
#else
static const int ddLogLevel = LOG_LEVEL_INFO;
#endif
其中if中是调试的时候的级别,下面else的级别是发布版本的时候的日志的级别,例如,我们希望向服务器抛出一些异常,那么我们就可以把debug级别设为LOG_LEVEL_VERBOSE 把发布版本的日志级别设为LOG_LEVEL_ERROR,这样在发布的时候,应用程序只会把用DDLogError输出的日志,写到文件中,文件在应用程序的沙盒路径的Caches的Logs文件夹中,我们要做的就是把这个文件夹发到服务器上。发布的方法如下
/**
* 获得系统日志的路径
**/
-(NSArray*)getLogPath
{
NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString * logPath = [docPath stringByAppendingPathComponent:@"Caches"];
logPath = [logPath stringByAppendingPathComponent:@"Logs"];
NSFileManager * fileManger = [NSFileManager defaultManager];
NSError * error = nil;
NSArray * fileList = [[NSArray alloc]init];
fileList = [fileManger contentsOfDirectoryAtPath:logPath error:&error];
NSMutableArray * listArray = [[NSMutableArray alloc]init];
for (NSString * oneLogPath in fileList)
{
if([oneLogPath characterAtIndex:0 ] == 'l')
{
NSString * truePath = [logPath stringByAppendingPathComponent:oneLogPath];
[listArray addObject:truePath];
}
}
return listArray;
}