go-ios icon indicating copy to clipboard operation
go-ios copied to clipboard

Be able to get the main app logs when use ios test command

Open ccouton opened this issue 2 years ago • 10 comments

Currently, when we use the "ios test" command line we can see the logs of the test but we cannot see the log of the mainapp.

ccouton avatar Nov 14 '22 21:11 ccouton

XCUITests run as a separate target with an additional proxy application installed on the device. If you run an XCUITest through Xcode you will get only the logs of the test as well and not the logs of the targeted application. IMHO we shouldn't print application logs while running XCUITest with ios runtest even if we have that possibility

shamanec avatar Nov 15 '22 06:11 shamanec

The application logs are output into the syslog for regular apps. So you can use go-ios syslog to view those.

For application extensions I haven't seen any reliable mechanism to get their logs thus far.

nanoscopic avatar Nov 18 '22 08:11 nanoscopic

XCUITests run as a separate target with an additional proxy application installed on the device. If you run an XCUITest through Xcode you will get only the logs of the test as well and not the logs of the targeted application. IMHO we shouldn't print application logs while running XCUITest with ios runtest even if we have that possibility

When we use xcode to run the test we have access to the both (UITest and MainApp) logs

ccouton avatar Nov 18 '22 13:11 ccouton

The application logs are output into the syslog for regular apps. So you can use go-ios syslog to view those.

For application extensions I haven't seen any reliable mechanism to get their logs thus far.

So you think that xcode use the syslog to get the app logs?

ccouton avatar Nov 18 '22 13:11 ccouton

I've studied the lockdown protocol extensively.

There are two different ways to access the syslog:

  1. Get the entire syslog streaming ( this is what go-ios is doing )
  2. Request syslog for only a specific process ( iosif does this, go-ios does not yet support it )

I don't think that Xcode uses syslog to get the app logs. I know that it does, through mechanism 2.

nanoscopic avatar Nov 19 '22 02:11 nanoscopic

You just have to add some env vars to the app process and it will log its logs via instruments. I hacked a first version here: https://github.com/danielpaulus/go-ios/pull/205 Will clean it up and make it a little more usable.

danielpaulus avatar Nov 19 '22 22:11 danielpaulus

Cleaned it up for the launch command. It does not work yet with XCTest, I am missing probably some stuff in the xctest config. Will check that soon and add it to the PR.

danielpaulus avatar Nov 19 '22 23:11 danielpaulus

Oh seems like I was wrong. Xcode does not print out the app under tests' logs if release mode. Go-iOS is based on release mode commands and does not use the debugger to connect to apps. I haven't played much with lldb also it is certainly interesting. I could try using syslog or the instruments logging next.

danielpaulus avatar Nov 20 '22 13:11 danielpaulus

@CedricCouton after reading this: https://stevenpcurtis.medium.com/logging-in-swift-d9b59146ff00 It seems like print only goes to the stdout of the app while NSLog and os_log are also going the the system log. I wonder, what are developers normally using? I will see if I can figure out how XCode uses the debugger to get the stdout of the app.

danielpaulus avatar Nov 21 '22 15:11 danielpaulus

Hi @nanoscopic and @danielpaulus. I had a similar (and somehow related) question. Is there a way to save the output of the tests, whilst using the "runtest" command? I can see the test outputs (not the device logs, which is obtainable using syslog) on the console when test is being run, but if I need to export the logs as well. I know we can write the logs to a file (either from the command line, OR write the output to a file in Go), but I was wondering if there's an option we can pass (perhaps an entry in the env file? 🤷🏻‍♂️) so that I don't reinvent anything :)

Thanks a lot and if anything please let me know :)

EDIT: If you think this is worthy of another issue, please let me know and I'll create it.

sepsky avatar May 23 '23 15:05 sepsky