(Resolved v88) PiHole log clearing bug

First of all a BIG thank you for the excellent work on putting PiHole on DietPi.

Have installed DietPi and installed PiHole. Using dietpi-software, the Log System is set at DietPi-Ramlog #2.

It began when I could not see the pihole.log in logfile_storage folder. The stats in <my.ip.address>/pihole were resetting every so often and the DNS query resolution would sporadically not resolve.

May have discovered a ‘bug’ in dietpi-logclear script in “/DietPi/dietpi” as it relates to the PiHole log file.

It seems that the script deletes all entries that do not match ‘today_date’ and restarts dnsmasq. On closer inspection the string returned by $(date +’%b %d’) is, for example ‘Sep 05’. However, in the PiHole log file the date is ‘Sep 5’ (two spaces between Sep and 5). This mismatch in format leads to the log file being purged every time ‘dietpi-logclear’ is executed and dnsmasq restarted. This would not be an issue if the date is say ‘Aug 12’.

Two issues emerge - the dns stats in the PiHole dashboard reset and restart of dnsmasq, causing a noticeable time delay dns query resolution while dnsmasq loads gravity.list.

FIX : Tried to use sed to change ’ 0’ to ’ ’ (two spaces). However, could not get it to work as it always returned a single space. So, had to do a simple hack such as below :

the format the above give is with a leading 0 in the date if the day is less than 10.

‘Sep 05’ instead of ‘Sep 5’. However, in the PiHole log file it is ‘Sep 5’

using sed gave a single space. Therefore, using the hack below.

local daylessthan10=$(echo “${today_date:4:1}”)

if [ $daylessthan10=‘0’ ]; then
local t_date=$(echo “${today_date:0:4}”)
t_date=$t_date$(echo " ")
today_date=$t_date$(echo “${today_date: -1}”)
Not elegant at all, but it works.

Hope this helps.


Hi Micky,

Firstly, your spot on with your findings and thanks for your input.

The dnsmasq log file uses space padding for 0’s in the day of the month. The previous dietpi-logclear code didnt allow for it, hence it would clear the whole logfile and restart dnsmasq every hour.

Everytime dietpi-logclear has to modify pihole.log, we need to restart the dnsmasq service. The reason for this is dnsmasq simply stops writing to the log file completely when another process is modifying the file. The only way to get dnsmasq to write back to the logfile is to restart the service.

All these issues have been resolved in a previous update:
Simply run dietpi-update on your device:
DietPi/CHANGELOG.txt at master · MichaIng/DietPi · GitHub.

Heres the updated dietpi-logclear code:

  • dietpi-logclear will now only restart dnsmasq if the day has changed, or, the logfile size exceeds 5MB (after clearing other days).
  • pihole.log file is not backed up with both dietpi-ramlog modes. This was left out due to the size, and, the issues with dnsmasq not writing to the logfile on modify.

Kind Regards,

Thanks Dan!