Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 775
Vadim Avatar asked Dec 14 '16 12:12

Vadim


People also ask

Where does NSLog write to?

NSLog outputs messages to the Apple System Log facility or to the Console app (usually prefixed with the time and the process id). Many of the system frameworks use NSLog for logging exceptions and errors, but there is no requirement to restrict its usage to those purposes.

What is Os_log?

In short, os_log makes it possible for you to add logs to your application in a more structured way. It allows you to filter your logs in the Console. app application. This way, you get a better view on why a certain error occurred. You can see it as an advanced version of the Xcode Console.

What is Os_activity_mode?

OS_ACTIVITY_MODE=disable. info, debug, disable. Sets the logging mode of the launched process to the specified level.


1 Answers

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"
like image 57
Vadim Avatar answered Sep 23 '22 00:09

Vadim