iOS - How to view NSLog and printf output in ssh s

2019-06-12 01:33发布

问题:

I have a simple iPhone App that uses an NSLog and several printf statements. The app is a simple test app that I created to test serial communication on the iPhone (3GS). Obviously I can not test serial com with the iOS Simulator, so I have my device unplugged from the computer after I click Run from within Xcode. I installed syslogd from Cydia, and tail /var/log/syslog allows me to monitor certain log messages.

However when I open my app and it reaches the NSLog portion of the code I don't see the message appear in /var/log/syslog I also don't see the printf statements output in the syslog file for the app.

Is there a file that exists on the iPhone itself that contains the output from these statements, or do I need to specify my app to output to /var/log/syslog?

I am content with opening another file if it exists on the phone that contains the contents of the log messages. Basically I want to be able to see the contents of the log messages while I am sshed into the phone so I can see what is going on. And obviously using the Console output in Xcode is not an option because the phone isn't connected to the computer.

回答1:

Are you using tail /var/log/syslog? It only shows the last 15 lines of the log. Maybe try using tail -f /var/log/syslog. I just tested that and it logged my my simple NSLog(@"LOL"); just fine. I was able to see it via ssh and everything.



回答2:

You write to syslog you should be calling the syslog function.

NSLog output can be seen as shown in this SO question.

printf will only go to stdout.

I would try not to use NSLog and stdout for logging in the same app - use NSLog for all logging there. Or with more work ue a logging framework like CocoaLumberjack that allows more flexibility including other loggers which could include syslog, thus having one logging function that you can redirect to different outputs at runtime.