从另一个应用程序获取 MacOSX 上的控制台日志
通过应用程序 Utilities/Console.app,我可以看到应用程序的控制台输出。
有没有办法从另一个应用程序访问此日志?
更具体地说:我正在为我的应用程序编写一个崩溃处理程序,我希望它将控制台输出附加到崩溃信息。
With the application Utilities/Console.app, I can see the console output of applications.
Is there a way to access this log from another application?
To be more specific: I am writing a crashhandler for my application and I want that it attaches the console output to the crash information.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
啊,刚刚发现有一个文件/var/log/system.log 包含这些信息。
Ah, just found out that there is the file /var/log/system.log which contains those information.
/var/log/system.log 并不是真正的解决方案,因为输出没有立即出现在那里(这是一个大问题,因为我的崩溃处理程序如何知道那里的一切都已完成),相关消息的 grep 也是非常hackish,然后,当我启动应用程序的几个实例时,我并不真正知道正确的相关输出(除非我知道pid,但即使如此,pid也不是唯一的)。
我非常满意的一个解决方案是应用程序本身正在跟踪所有控制台输出。它通过分叉自身并将其输出传送到分叉并模拟那里的 tee 工具来实现这一点,其中一个输出是一个特殊的日志文件。当它崩溃时,它将日志文件的文件名发送到崩溃处理程序。
如果您有兴趣,请查看 OpenLieroX 源代码 ( http://sourceforge.net/projects/openlierox ).
/var/log/system.log was not really a solution because the output didn't immediatly appeared there (which was a big problem because how should my crash handler know that everything is complete there), also the grepping of the related messages was very hackish and then, when I started several instances of the application, I didn't really know about the correct related output (unless I knew the pid but even then, also the pid is not unique).
Know, a solution I am very happy with, is that the application itself is keeping track about all the console output. It is doing that by forking itself and piping its output to the fork and emulating the tee tool there, where one output is a special log file. When it crashes, it sends the filename of the logfile to the crashhandler.
If you are interested, look at the OpenLieroX source code ( http://sourceforge.net/projects/openlierox ).