2

I am using xcodebuild to test my application in CI. I invoke it like this:

xcodebuild test -project myapp.xcodeproj -scheme myappTests -destination 'platform=iOS Simulator,name=iPhone 8,OS=14.4'

Text logged with the Logger from OSLog are not shown in debug level. So if I have something like this in my test, it isn't shown in the output of xcodebuild, but I would like to see that:

Logger(subsystem: "a", category: "b").debug("something")

Can I set the logging level of xcodebuild to debug? Messages with error level are shown.

I tried setting xcodebuildDebugLogLevel=3 but that gave me the same logging information.

iUrii
  • 11,742
  • 1
  • 33
  • 48
J. Doe
  • 12,159
  • 9
  • 60
  • 114

1 Answers1

2

Logger doesn't print debug (and trace) messages to the output because a log level of your subsystem on your simulator is INFO.

You can check this with next steps:

  1. Find your simulator UDID that you use for tests:
$ xcrun simctl list
...
-- iOS 15.2 --
    iPhone 8 (C1D16369-D358-438E-8395-D01C2DE55980) (Shutdown) 
...
  1. Boot it if needed
$ xcrun simctl boot C1D16369-D358-438E-8395-D01C2DE55980
  1. Check a log level of your subsystem name:
$ xcrun simctl spawn C1D16369-D358-438E-8395-D01C2DE55980 log config --subsystem <your-subsystem-name> --status
Mode for '<your-subsystem-name>'  INFO PERSIST_DEFAULT

To change the current log level to DEBUG you can use next command:

$xcrun simctl spawn C1D16369-D358-438E-8395-D01C2DE55980 log config --subsystem <your-subsystem-name> --mode level:debug

Check again:

xcrun simctl spawn C1D16369-D358-438E-8395-D01C2DE55980 log config --subsystem <your-subsystem-name> --status 
Mode for '<your-subsystem-name>'  DEBUG PERSIST_DEFAULT

Now your tests with xcodebuild must have all debug (and trace) messages in the output.

Note: Console.app doesn't provide debug/trace messages even after changes from abobe and it's old known issue with simulators.

iUrii
  • 11,742
  • 1
  • 33
  • 48
  • What should I substitute with ? When I fill in the subsystem of the value which I create the Logger with, I get this terminal error: An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=2): The operation couldn’t be completed. No such file or directory No such file or directory – J. Doe Jan 29 '22 at 12:45
  • @J.Doe Usually should be in reverse DNS notation, such as com.your_company.your_subsystem_name. Which command fails? – iUrii Jan 29 '22 at 20:15