如何将stdout放入Console.app [英] how to get stdout into Console.app
问题描述
以前,我可以从Console.app中的应用程序读取所有stdout/stderr数据.一段时间以来,情况已不再如此(不过,NSLog数据仍然存在).我现在是10.8.
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.
有一个 2010年以前的类似问题,它没有似乎不再是最新的了.
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.
是否已更改,即不再应该记录stdout?还是在我的系统上发生了故障(从旧的SU问题来看,听起来可能是这种情况-尽管没有帮助)?
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?
推荐答案
在Mountain Lion之前,由launchd
管理的所有进程(包括常规应用程序)的stdout和stderr文件描述符都转发到系统日志.在Mountain Lion及更高版本中,对于launchd
托管的应用程序,stdout和stderr无处可去.只有明确发送到系统日志的消息才会在那里结束.
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.
如果您正在编写应用程序,并且希望在控制台中显示一些输出,则采用基于 asl(3)
代替. NSLog
是这样的一种API,它也具有登录到stderr的优点,因此无论您如何启动应用程序,您都可以轻松查看输出.如果您想要该功能但想直接使用asl
或syslog
,则需要分别查看asl_open
的ASL_OPT_STDERR
选项和openlog
的LOG_PERROR
选项.
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.
这篇关于如何将stdout放入Console.app的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!