Turning a log file into a sort of circular buffer
I have a daemon application that prints to stdout/stderr its logs. I am looking for a way to keep the last N lines of log in memory, and access them on demand, ideally with something simple like cat. This logs don't have to be persisted to disk.
Basically I'd love to be able to do something like:
./mydaemon.sh | memlog 100 mydaemonlog &
and then, afterwards:
and I would get the last 100 lines of log, and then it would keep printing the log as it gets piped in the
Is there some tool that is able to do what
memlog is doing in the example above?