Linux : Rotating log buffer with output redirection

Posted on

Problem :

I have an application that prints errors on stderr. I can redirect that output to a file with

app 2> log.txt

(Un)fortunately I log tons of information. I’d like log.txt to not grow too much, or it will break my tiny ramdisk. Is there any way to have some kind of rotating log like this?

In my ideal scenario, log.txt will always be of 100kb size, containing latest output only.

I know that POSIX systems are all pipes and filters and I figured that it is something a lot of people would want to do so is there some way to do this with basic linux commands? I say basic because I can’t really rely on packages since I’m on an arm9 system and cross compiling is sometimes difficult.

On a sidenote, I don’t have cron on my system =(

Solution :

Get yourself one or more of:

None of them requires cron; none requires syslog or anything more than ordinary pipes; and all do exactly what you want to do: turning standard input into a set of automatically rotated and size limited log files.