How do you implement a fixed-capacity ring buffer that overwrites the oldest entry (e.g. last N log lines)?