How to log to OSX

How do I log messages from my app such that they will appear in the OSX

OfLog() doesn’t seem to do it, and just shows a message in Xcode’s log.

You should log to a file, and then open that file in the OS X Console. If you use the file extension “.log” will automatically open the file when double clicking it in Finder.

See ofLogToFile:!show_ofLogToFile

@eelke, thanks.

Is there any concern for very long running installations (10 years) that writing to the log file could become slow if the file becomes large eventually (several gigabytes?) or is there no performance penalty to append to a long file?

Hi @smoothmango, I think it depends on what you plan on doing with the log files, and the installation as a whole. Do you really want to log everything the installation does, day in day out and be able to know what it did on a Thursday morning 4 years ago?

Some things to consider:

  • Every time the application starts, it can start logging to a new file. For instance, use the current timestamp to create a filename. If you intend on keeping the app running without reboots, you can still do this by setting a new filename on your preferred interval (ie. every day at 12pm for instance).
  • When using the same log file over and over, ofLogToFile can either append the lines to the existing file, or erase the previous content and start from scratch, see the documentation above.
  • You can write a little script that deletes old files. We usually keep 1 log file per day (auto reboot the whole system), and erase files older than 30 days.
  • by default will only load and show the last 15mb (I think) of any log file, so larger files are no problem. However, there is disk space to consider, and your oF app might slow down when trying to write to large files (not sure about that)

I did some calculations, and my log file growth rate is about 1kb/day, so it should only grow to about ~4MB in a decade. I think I’m going to take the lazy route and just log to a single file forever. Your other suggestions are excellent though, thanks @eelke !