现代的日志记录API可在终端轻松配置.但是, Xcode似乎输出所有级别,包括INFO和DEBUG,这非常烦人.因为大多数时候你只想看到os_log_error和NSLog又称“出了问题”和“这很重要”. 那么有没有办
那么有没有办法只在Xcode控制台中显示特定级别?
os_log_info(OS_LOG_DEFAULT, "Info"); os_log_debug(OS_LOG_DEFAULT, "Debug"); os_log_error(OS_LOG_DEFAULT, "Error"); os_log_fault(OS_LOG_DEFAULT, "Fault"); os_log(OS_LOG_DEFAULT, "Default"); NSLog(@"NSLog");
当前输出:
2016-12-14 15:37:00.170807 Test[5681:2205834] Info 2016-12-14 15:37:00.170830 Test[5681:2205834] Debug 2016-12-14 15:37:00.170835 Test[5681:2205834] Error 2016-12-14 15:37:00.170839 Test[5681:2205834] Fault 2016-12-14 15:37:00.170860 Test[5681:2205834] Default 2016-12-14 15:37:00.170869 Test[5681:2205834] NSLog
首选输出:
2016-12-14 15:37:00.170835 Test[5681:2205834] Error 2016-12-14 15:37:00.170839 Test[5681:2205834] Fault 2016-12-14 15:37:00.170860 Test[5681:2205834] Default 2016-12-14 15:37:00.170869 Test[5681:2205834] NSLog我使用过DTS并得到了Apple工程师的答案:
The new unified logging system is a relatively recent addition and, alas, Xcode has not yet caught up with it. If you’d like to see a future version of Xcode support log filtering, I encourage you to file an enhancement request describing your requirements.
所以请复制rdar:// 28288063,请求越多越好.谢谢!
更新:如下面的Max所述,您可以修改自定义日志的可见性:
os_log_t custom = os_log_create("com.acme.demo", "custom"); os_log_info(custom, "Info"); os_log_debug(custom, "Debug"); os_log_error(custom, "Error"); os_log_fault(custom, "Fault"); os_log(custom, "Default");
以下Terminal命令将禁止Xcode中的“Info”和“Debug”字符串:
sudo log config --mode "level:default" --subsystem "com.acme.demo"
要重置系统默认值:
sudo log config -reset --subsystem "com.acme.demo"
要检查当前状态:
sudo log config --subsystem "com.acme.demo"