Forum

Log size limit

Praseed
20 October 2011, 02:21
Hi Hugo,
As we cannot have limitless size for log files in embedded systems, it would be great to have configurable log file size limit.
Hugo Leisink
20 October 2011, 14:12
Is logrotate an acceptable solution?

Problem with limiting logfiles is: what to do when the maximum size is reached? Stop logging? Not acceptable. Remove first lines of logfile before writing new ones? Requires loading logfile in memory, removing first lines and writing it back. To slow, memory consuming, possible conflicts with multiple threads wanting to write to the same logfile.

As you can see, the solution to this problem is not easy.
Praseed
20 October 2011, 18:08
My suggestion is to make it two configurable values for log files
1) Max log file size
2) No: of files
Example:- File access.log
Max log size set to 5MB & no: of files set to 5. (so max disk space used at any given time cannot exceed 25MB for access.log)
Now, access.log reaches the file size limit, move it to access.1.log & create new access.log.
If this new access.log reaches the limit. move access.1.log to access.2.log & then move access.log to access.1.log.
Keep going like this till the file number limit is reached & then start deleted the oldest file when file no: limit exceeds.
I've seen this widely used in multiple products.

Thanks
Praseed
Hugo Leisink
20 October 2011, 19:05
What you describe is exactly what logrotate does. My advice is to use that.
Praseed
20 October 2011, 19:18
OK thanks Hugo..
let me check it out.
This topic has been closed.