Log Level | Suggested Usage |
---|---|
Emergency (level 0) | The highest priority, usually reserved for catastrophic failures and reboot notices. |
Alert (level 1) | A serious failure in a key system. |
Critical (level 2) | A failure in a key system. |
Error (level 3) | Something has failed. |
Warning (level 4) | Something is amiss and might fail if not corrected. |
Notice (level 5) | Things of moderate interest to the user or administrator. |
Info (level 6) | The lowest priority that you would normally log, and purely informational in nature. |
Debug (level 7) | The lowest priority, and normally not logged except for messages from the kernel. |
这个等级有什么用处呢?根据苹果文档描述,只有level 0和1的日志,才会被存入到database,其他的日志将不会保存。
我们常常希望在机器上获取日志,有一个开源软件叫做 consoleme,它可以在真机上查看日志。但是在ios7系统以后,很多日志都看不到了,这应该是苹果系统的调整。所以为了能看到日志,要调整NSLog输出的等级。
ok,让我们来尝试一下,这个想法是否会成功。
查询文档,苹果提供了asl_log()这个底层函数,相关文档
#define DebugLog( s, ... ) asl_log( NULL, NULL, (1), "%s", [[NSString stringWithFormat:@"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__]]UTF8String] ) |
经尝试调整asl log的等级,在真机上还是无法读取到。看来现在苹果只允许读取应用内的日志。
解决办法:在应用内读取自己的日志。可以用asl相关的函数,asl_search等
-----------------------------
log相关的开源第三方库
https://github.com/aharren/LibComponentLogging-LogFile-Example
http://labs.grupow.com/blog/2010/12/02/objective-c-logging-with-sosmax/