18

Earlier, I could read all stdout/stderr data from applications in Console.app. Since a while, this is not the case anymore (NSLog data is still there, though). I'm on 10.8 now.

There was an earlier similar question from 2010 which doesn't seem up-to-date anymore.

On SU, there is also a similar question which wasn't yet answered.

Has that been changed, i.e. stdout is not supposed to be logged anymore? Or is something broken on my system (from the old SU question, it sounded like that might be the case - although without being helpful)?

Can I somehow change it back?

Community
  • 1
  • 1
Albert
  • 65,406
  • 61
  • 242
  • 386

2 Answers2

21

Prior to Mountain Lion, all processes managed by launchd, including regular applications, had their stdout and stderr file descriptors forwarded to the system log. In Mountain Lion and above, stdout and stderr go nowhere for launchd managed applications. Only messages explicitly sent to the system log will end up there.

If you're writing an application and would like some output to show up in the console, then adopt an API built on syslog(3) or asl(3) instead. NSLog is one such API, and it has the advantage of logging to stderr too so you can easily see your output no matter how you've launched your application. If you'd like that functionality but want to use asl or syslog directly then you'll want to look in to the ASL_OPT_STDERR option to asl_open, and the LOG_PERROR option to openlog respectively.

bdash
  • 18,110
  • 1
  • 59
  • 91
  • Do you have any reference about that this behavior changed in `launchd` and why it changed? – Albert Mar 27 '13 at 15:06
  • 3
    I don't have any real reference, but you can confirm the change by taking a look at the [launchd source releases](http://opensource.apple.com/source/launchd/). You can see that references to `log_redirect_fd` and `job_log_stdouterr` that were present in OS X 10.7.5's launchd-392.39 are no longer present in launchd-442.21. This was the logic that was responsible for reading the application's stderr and stdout descriptors and forwarding their output to the system log. – bdash Mar 27 '13 at 16:52
  • So what is the solution for compatibility with code that uses stderr? – Asher Nov 02 '22 at 20:31
3

If you have an old app and want to see stdout or stderr, open the app from Terminal. You can wind your way to the executable and open it from the command line, like in the normal, old world: type the program name. Then the messages will appear on the terminal.

This is not a repudiation of any of the other, better suggestions. It is just a way to get the output without altering the (old) program.