views:

122

answers:

1

I'm using Google toolbox for Mac's GTMLogger to do logging to file in the app I'm working on.

I'm trying to decide how to do log file rollover when the file gets large enough.

Ideally I would like something like log4net's immediate rollover when the log file hits 1 mb with max 11 log files at any one time, but I don't see any built-in way to do this and I'm wondering if trying to add it is more trouble than it's worth.

The somewhat simpler option I can think of is just doing this check on app start-up and rolling over the log it it's over a certain size. The downside to this is of course if somebody leaves the app running for a week or two (and since a portion of the app is a launchd daemon this is a definite possibility for those who rarely restart), there could be a log file of non-trivial size built up during this period (depending on what logging level is enabled).

What's going to be my best option here?

+1  A: 

You're worried that checking only at startup might not be often enough. So, throw a timer in your runloop at startup to trigger a log check immediately and once every day or two thereafter. If you're targeting using at most 1 MiB at a time, even if you do go over limit for a while, it likely won't matter all that much.

You could also just look at how log4net implements this feature: it's as simple as hooking each Append() to check that the size/date constraints are being met and adjusting the file logged to if necessary. See the RollingFileAppender source code for further details; start with AdjustFileBeforeAppend() and then check out RollOverSize(). It's Apache: Use the source!

Jeremy W. Sherman