Search code examples
objective-ciosdevicenslog

NSLog ignored on devices


I am trying to redirect all NSLog output to be able to see all my logs in a UITextView inside the app (for debug purposes, and maybe later to log everything using TestFlight). I can't use the well-known DLog because I want to catch logs from frameworks I don't own.

I'm doing this by 'redirecting' stderr to a pipe and reading from this pipe. Anyway, this works well on the simulator and on the device when the app is launched from within Xcode. But, this does not work when the app is launched "by hand" on the device.

It seems that NSLog calls have no effect on the device: I don't read anything from the pipe. However, if I manually write on stderr : fprintf(stderr, "test") I can read it from the pipe, so the problem is not with stderr but rather with the NSLog function.

Why does it do nothing on devices ? Is there a way to make it write on stderr even on the device ?

If it is not possible to use NSLog on devices, is there another way to gather logs from external frameworks ?

Thank you.


Solution

  • NSLog goes to the system log on devices. You can access the system log using the C API asl (Apple System Log); also check out this blog post.

    However if you're using TestFlight it's much easier to just replace/append those NSLog statements with the TFLog statement.

    TFLog(@"This comment is live on TestFlight.");