D.C.
D.C.

Reputation: 15588

How do i implement file logging such that the logs do not grow unbounded?

I am working on a daemon that runs on a schedule, every few minutes. I want it to log out to a file about what it's been up to. However, I don't want the log to keep growing forever. It'd be nice if it just kept the last 200 or so tasks. Is there a conventional way to accomplish this, or do I need to write code to monitor the size of the log file and delete some of it when it gets too large?

I should mention I'm writing this to run on OSX. It will use Foundation / Objc.

Thanks for the help.

Upvotes: 0

Views: 51

Answers (1)

Mike Lischke
Mike Lischke

Reputation: 53437

A typical solution is log rotation. On certain conditions (like a new day starts) the current log is closed and renamed. After that a new current log is created. You can also limit the number of old log files to a reasonable amount (or let the user decide).

Upvotes: 1

Related Questions