真机查看NSLog

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()这个底层函数,相关文档

https://developer.apple.com/library/ios/documentation/System/Conceptual/ManPages_iPhoneOS/man3/asl.3.html

https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/LoggingErrorsAndWarnings.html#//apple_ref/doc/uid/10000172i-SW8-SW7

#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/

https://github.com/CocoaLumberjack/CocoaLumberjack

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值