71

How can I monitor what logrotate is doing in Ubuntu? Can the activity of logrotate be monitored?

w5m
  • 151
  • 8
  • well you could go and see which file descriptors the process has opened... Maybe try to explain what exact problem you have? Are you trying to debug your own scripts? Performance of default/3rd party scripts? – Hubert Kario Oct 09 '10 at 15:31

5 Answers5

80
cat /var/lib/logrotate/status 

To verify if a particular log is indeed rotating or not and to check the last date and time of its rotation, check the /var/lib/logrotate/status file. This is a neatly formatted file that contains the log file name and the date on which it was last rotated.

Taken From:

https://www.digitalocean.com/community/articles/how-to-manage-log-files-with-logrotate-on-ubuntu-12-10

Camilo Sanchez
  • 903
  • 6
  • 7
  • 24
    You'll find this file as `/var/lib/logrotate.status` on Red Hat systems. – Michael Hampton Jun 24 '13 at 16:07
  • 1
    here's a complete guide to troubleshooting logrotate in Red Hat systems: https://access.redhat.com/solutions/32831 – Gaia Feb 23 '15 at 19:17
  • 1
    Considering Ubuntu, `cat /var/lib/logrotate/status ` only shows [logrotate activity initiated by the root user](https://unix.stackexchange.com/a/169029/20230). Other users' cronjobs may trigger their own logrotate activity, e.g. when their crontab includes an entry such as `0 0 * * * /usr/sbin/logrotate $HOME/logrotate/logrotate.conf --state $HOME/logrotate/logrotate-state`. That logrotate activity would be written to file `$HOME/logrotate/logrotate-state`, with `$HOME` being that user's home directory. – Abdull Jun 05 '18 at 12:06
  • 5
    In even more recent RedHat systems (at least in RHEL 7.6) the status file is now at `/var/lib/logrotate/logrotate.status` . – Richlv May 31 '19 at 15:27
18

You can try running logrotate in debug or verbose mode:

-d     Turns  on  debug mode and implies -v.  In debug mode, no changes
          will be made to the logs or to the logrotate state file.

-v, --verbose
          Display messages during rotation.
kernelpanic
  • 1,246
  • 1
  • 10
  • 30
  • Does this help this when logrotate is started as cron? I mean is there a possibility to log the behaviour of logrotate to a logfile? –  Oct 09 '10 at 15:45
  • 2
    /usr/sbin/logrotate -v /etc/logrotate.conf &> /var/log/logrotate.log – kernelpanic Oct 09 '10 at 15:55
  • sudo logrotate -v /etc/logrotate.conf &> /var/log/logrotate.log bash: /var/log/logrotate.log: Permission denied –  Oct 09 '10 at 16:01
  • 1
    @dude: If you're trying to do that from the command line and you're getting that error, you'll need to do it like this: `sudo logrotate -v /etc/logrotate.conf 2>&1 | sudo tee -a /var/log/logrotate.log >/dev/null` (make **sure** you have the `-a`). – Dennis Williamson Oct 09 '10 at 23:53
  • @Dennis when i try that i although creates the logrotate.log but it has 0KB and the process doesn't stop at the terminal and and waits with a blinking cursor. –  Oct 10 '10 at 10:39
  • Simpler way to sudo with redirection: `sudo bash -c 'logrotate -v /etc/logrotate.conf &> /var/log/logrotate.log'` – Stevel Sep 18 '20 at 13:48
10

In Suse Linux distros is like this:

cat /var/lib/logrotate.status
Watchmaker
  • 729
  • 1
  • 7
  • 16
5

You can check the settings of logrotate, usually in /etc/logrotate.conf.

Modern distros have a specific logrotate configuration file in the /etc/logrotate.d directory.

e.g. for nginx

  /var/log/nginx/*.log {
    weekly
    missingok
    rotate 52

It will keep the file for 52 weeks (a year). The rotation is weekly.

Déjà vu
  • 5,408
  • 9
  • 32
  • 52
5

Various logs are rotated on various frequencies based on the configuration file (/etc/logrotate.conf) and/or directory (/etc/logrotate.d). Names may vary on different distributions. The configuration may specify pre and/or post rotation actions. Names of rotated files and last rotation date are in the state file (/var/lib/logrotate/state).

Logrotate does not have logging facilities. Reload/restart actions it initiates will be logged according to the logging for the program being acted on.

The easiest way to do that would be to edit /etc/cron.daily/logrotate to include the -v option. Detail about logrotate configuration and options can be found with the command man logrotate.

BillThor
  • 27,354
  • 3
  • 35
  • 69