0

I have a similar question to this one which doesn't appear to have a happy resolution. It mentions using rotatelog.exe which is part of the Apache framework and not available to me.

I have inherited a Windows 2012 R2 web server from my predecessor, it is serving out PHP files via IIS 8.5. I recently tried to diagnose a problem with one of our sites only to discover the PHP error log was several GB in size (dating back to 2013).

Ideally I would like to rotate these logs on a daily or monthly basis.

How can I achieve this? PHP is 5.4, but a method for any version would be acceptable.

Burgi
  • 150

1 Answers1

0

I solved this with a batch script and adding the script to the task scheduler to run daily. I am aware I could write this in PowerShell but I am not familiar enough with the shell to do this.

This is my batch script:

:: Batch script to rotate PHP logs
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS

SET logPath=c:\php\logs\
SET currentLog=PHP54_errors.log

FOR /F %%A IN ('WMIC OS GET LocalDateTime ^| FINDSTR \.') DO @SET B=%%A
MOVE %logPath%%currentLog% %logPath%%B:~0,4%-%B:~4,2%-%B:~6,2%.log
Burgi
  • 150