# Implement logrotation for /var/log/pihole.log

**URL:** <https://discourse.pi-hole.net/t/implement-logrotation-for-var-log-pihole-log/1266>\
**Category:** Implemented\
**Created:** [January 12, 2017, 7:32am UTC](https://discourse.pi-hole.net/t/implement-logrotation-for-var-log-pihole-log/1266 "2017-01-12T07:32:10Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![DL6ER](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/dl6er/32/281_2.png) [@DL6ER](https://discourse.pi-hole.net/u/DL6ER)\
**Post date:** [January 13, 2017, 10:15am UTC](https://discourse.pi-hole.net/t/implement-logrotation-for-var-log-pihole-log/1266/6 "2017-01-13T10:15:52Z")

</div>

> [@jpgpi250](#):
>
> Warning: I choose copytruncate because logging didn't resume using other options (always had to restart dnsmasq). My log is about 600Kb in size, I've got no idea what will happen if the log is several Mb in size. This should be tested!

I have a log that is several MB in size (about one dozen quite active clients). It works without problems. `dnsmasq` keeps the log file open while running and therefore if you move the file it will happily write into the moved file instead of the new one (as the pointer to the virtual memory location does not change and renaming does not change where the file is physically located but only its name).

> [@jpgpi250](#):
>
> I would advise against the @reboot cron option, als the log will be rotated at every reboot, witch I (and others) often do when I'm testing things.

I tested this already (you can see it is in the code of the pull request): The log has been flushed at midnight. When I reboot, `logrotate` states that the file is not older than one day and simply skips the rotation procedure without having us to worry about it. Tried with three reboots within an hour - no rotation happened for me - did you see something different that would require implementing the changes you suggested (with checking the date)?

EDIT: You can see this when running the command manually with the verbose option:

```auto
# /usr/sbin/logrotate -v /etc/.pihole/advanced/logrotate
reading config file /etc/.pihole/advanced/logrotate

Handling 1 logs

rotating pattern: /var/log/pihole.log after 1 days (5 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/pihole.log
  log does not need rotating

```

(note that the log was several hundred KB is size at this time, so the line about empty log files is only informative)

---

_[View the full topic](https://discourse.pi-hole.net/t/implement-logrotation-for-var-log-pihole-log/1266)._
