问题描述
我正在编写第一个在后台工作的Objective-C守护程序类型的过程.它所做的一切都需要正确记录.
I am writing my first objective-c daemon type process that works in the background. Everything it does needs to be logged properly.
我对Apple知识还很陌生,所以我不确定,最常见和/或最好的记录活动的方法是什么?每个人都只是简单地以自己的特殊格式登录到文本文件,还是使用某种系统调用?
I am fairly new to Apple stuff so I am not sure, what is the most common and/or best way to log activity? Does everyone simply log to a text file in their own special format, or use some sort of system call?
推荐答案
您应该查看 Apple系统记录器. ASL会写入系统日志数据库(可以轻松地从Console.app或您自己的应用程序中查询日志),还可以写入一个或多个平面文件(如果您选择的话).彼得·霍西(Peter Hosey)对ASL的简介是我所知道的最好的. ASL是一种C级API,但是如果您愿意,可以将它包装在Objective-C中相对容易.我还建议您还看看 Google Mac版工具箱.在许多其他功能中,它包含GTMLogger
工具,其中包括ASL支持.我放弃了自己的ASL包装程序,转而使用GTMLogger
.
You should look at the Apple System Logger. ASL writes to the system log database (making it easy to query the log from Console.app or from within your own app) and additionally to one or more flat files (if you choose). Peter Hosey's introduction to the ASL is the best I'm aware of. ASL is a C-level API, but it's relatively easy to wrap in Objective-C if you'd like. I would recommend also taking a look at Google's Toolbox for Mac. Among many other goodies, it contains a GTMLogger
facility that includes ASL support. I've ditched my home-grown ASL wrapper in favor of the GTMLogger
.
这篇关于Objective-C记录最佳做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!