0

Possible Duplicate:
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:

cat /some/path/here/mydaemonlog

and I would get the last 100 lines of log, and then it would keep printing the log as it gets piped in the mydaemonlog file.

Is there some tool that is able to do what memlog is doing in the example above?

CAFxX
  • 103
  • 5
  • Is necessary to have N lines of log in memory? Or you want a solution to write the log to the disk ? – Sacx Nov 20 '12 at 11:59
  • @Sacx I don't need them persistent or on disk. I could write them on disk and the perform log rotation, but it seems hopelessly inelegant. – CAFxX Nov 20 '12 at 12:30
  • @MadHatter you're right. Flagged as duplicate. Thanks. – CAFxX Nov 20 '12 at 12:31

2 Answers2

0

You might output logs to /dev/shm and then use tail to get last n lines.

./mydaemon.sh >/dev/shm/log
tail -100 /dev/shm/log
FINESEC
  • 1,371
  • 7
  • 8
0

Have in-memory sqlite database. The script managing it can make sure only 100 rows are on there at a time.

belteshazzar
  • 302
  • 4
  • 9