I want my Mac Os X sandboxed application to write a log file of every action it takes, I think the correct path would be /Users/MyName/Library/Containers/com.me_developer.myAppID/Data/Library/Logs/. I know how to write a file a append text to it, but what I am looking for is to have old log files archived in a manner similar to system log files are written in /var/log , once they reach a certain size, they are renamed, and compressed (bz2). I wonder if Mac Os X or its lower levels UNIX offers a built in solution for that, and so I wouldn’t have to write manually all the code. Thanks.
Share
Take a look at asl, which is the API for interacting with the system log facility in Mac OS X (and iOS). It’s a bit low level, in that it’s a C API, but it should do everything you want and does so in an Apple-sanctioned, sandboxing-compatible way.
There are a number of third-party, open source Objective-C wrappers for ASL. Here are a few examples (I haven’t used any of these, myself):
https://github.com/AlanQuatermain/aqtoolkit/tree/master/ASLogger
https://github.com/billgarrison/SOLogger
https://github.com/nloko/NLOSyslog
Here’s a couple articles/tutorials about using ASL:
http://boredzo.org/blog/archives/2008-01-20/why-asl
http://www.cocoanetics.com/2011/03/accessing-the-ios-system-log/
Finally, be sure to take a look at Cocoa Lumberjack, which is a very popular Cocoa logging library.