# LogRotate

#### LogRotate Configuration.

**https://www.redhat.com/sysadmin/setting-logrotate**

If not installed already (it usually is), install the logrotate service:

apt install logrotate

yum install logrotate

#### **Configuration of logrotate**

/etc/logrotate.conf - used to define default parameters for logrotate

/etc/logrotate.d - used for configuring logrotate for specific logs

example configuration:

```
/root/.unison/unison.log {
    rotate 7
    daily
    compress
    missingok
    notifempty
}
```

Common options you may see used in a configuration file include:

- `<span class="pre">compress</span>` - this indicates the log files should be compressed once rotated. `<span class="pre">gzip</span>` is used by default.
- `<span class="pre">daily</span>` / `<span class="pre">weekly</span>` / `<span class="pre">monthly</span>` / `<span class="pre">yearly</span>` - this specifies that the log file should be rotated every day, week, or month.
- `<span class="pre">ifempty</span>` / `<span class="pre">notifempty</span>` - these specify whether to either rotate the log file even if it’s empty, or to not rotate the log file if it’s empty, respectively.
- `<span class="pre">missingok</span>` / `<span class="pre">notmissingok</span>` - these options will either not generate an error, or will generate an error if the log file does not exist. `<span class="pre">notmissingok</span>` is the default.
- `<span class="pre">rotate</span>` - this is supplied with a number argument, which specifies how many times the log files are rotated before being removed.
- `<span class="pre">size</span>` - this specifies the size a log file has to reach before it is rotated.

#### Running LogRotate

LogRotate usually comes set up with a daily cron:

```
ls /etc/cron.daily/
apport  apt-compat  dpkg  logrotate  man-db  plocate
```

You can also run a logrotate configuration at any time:

```
logrotate name
```

<div id="bkmrk--1"><div class="cm-editor ͼ1 ͼ3 ͼ4 ͼo">  
</div></div>