Search code examples
loggingsystemdjournal

Pipe output of journalctl -f into file but with limited file size


I would like to pipe journalctl -f -o json into file but don't size gets very big after some time? Can I set it somehow to rotate?

Command:

journalctl -f -o json>> /tmp/myFile &

Lets say that after reaching size of 10 MB or after reaching 2000 lines I would like to rotate log.

Is there some simple command to do that or it require shell/python script running?


Solution

  • Apache Rotatelogs (part of Apache Webserver distribution) is what you are searching for. It's a versatile tool, not limited to webserver logfiles:

    journalctl -f -o json | rotatelogs "journal-%c".json 10M