>_ IzzyLab

Hands-on task

This task is step 15 of the course “Logs: analysis and housekeeping”

Size-based logrotate for the queue log

medium~7 min

The queue worker writes to /var/log/queue/worker.log, and the log is already past 3 MiB. Describe its rotation in /etc/logrotate.d/queue-worker: rotate only when the log is bigger than 500k, keep 5 old copies, compress them, and create a new empty worker.log after rotation.

What you'll practise:
  • logrotate
  • size-based rotation
  • size
  • compress
  • create

Topic breakdown

logrotate fires on a threshold: by schedule (daily, weekly) or by file size. A size threshold suits logs that grow in bursts: while the file is under the threshold, rotation is skipped even if it was run. On rotation the current file is renamed to .1, the old copies shift, and the ones over the limit are deleted; compression saves space on the archives. The directive that creates a new file is needed when the process writes by path rather than holding a descriptor: without it there simply won't be a log in place after rotation. The -d mode shows logrotate's decision without doing anything — handy for checking a config.

What's checked

  1. the /etc/logrotate.d/queue-worker config describes the worker log
  2. 5 compressed copies are kept
  3. rotation fires only past 500k
  4. a forced rotation gives worker.log.1.gz
  5. a new empty worker.log is in place of the log

What it looks like