How do you disable os_log_info and os_log_debug messages in Xcode console?

三世轮回 提交于 2020-01-23 01:20:11

问题


Modern API for Logging is easy configurable in Terminal. However, Xcode seems to output all levels including INFO and DEBUG which is very annoying. Because most of the time you want to see only os_log_error and NSLog aka “something went wrong” and “this is important”.

So is there any way to display only particular levels in Xcode Console?

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");

Current output:

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

Preferred output:

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

回答1:


I have used DTS and got the answer from an Apple engineer:

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.

So please duplicate rdar://28288063, the more requests the better. Thanks!


Update: As noted by Max below, you can modify visibility for custom logs:

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");

The following Terminal command will suppress “Info” and “Debug” strings in Xcode:

sudo log config --mode "level:default" --subsystem "com.acme.demo"

To reset system defaults:

sudo log config -reset --subsystem "com.acme.demo"

To check current status:

sudo log config --subsystem "com.acme.demo"



回答2:


You can switch debug-level in terminal:

$ sudo log config --mode "level:debug" --subsystem com.your_company.your_subsystem_name

To check your current level:

$ sudo log config --status --subsystem com.your_company.your_subsystem_name
Mode for 'com.your_company.your_subsystem_name'  DEBUG

For more information see Apple Documentation



来源:https://stackoverflow.com/questions/41142848/how-do-you-disable-os-log-info-and-os-log-debug-messages-in-xcode-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!