In the folder bin
of the Apache exists the rotatelogs
This program is useful for generating rotational logs.
Apache rotatelogs
Here’s an example of how to generate 1 log file per day:
<IfModule log_config_module>
LogFormat "%h %l %u %{%Y-%m-%d %H:%M:%S}t \"%r\" %>s %b \"%{Referer}i\"" combined
CustomLog "|bin/rotatelogs.exe C:/www/site/logs/access/log_access-%Y-%m-%d.txt 86400 +000" combined env=!dontlog
</IfModule>
Remarks:
1. Even under Windows environment, the path should use normal bar.
2. The path of rotatelogs should be relative, in Windows environment, and should start with the vertical bar |
.
C:/www/site/...
Not do with backslash:
C:\www\site\...
The logs will be generated according to the format log_access-%Y-%m-%d.txt
log_access-2016-08-29.txt
log_access-2016-08-30.txt
log_access-2016-08-31.txt
You can also restrict by file size. For example, generate a new log file every 1mb. See the options in the documentation: https://httpd.apache.org/docs/2.4/programs/rotatelogs.html
If you just want to deactivate:
#CustomLog "|bin/rotat...
A simple Sharp (#) disables the line.
Obs: Normally in a development environment there is not much reason to save access logs using Apache log resources.
The most interesting can be to save error logs. For this follows the same form. Just apply it to the parameter ErrorLog
.
ErrorLog "|bin/rotatelogs.exe C:/www/site/logs/errors/log_error-%Y-%m-%d.txt 86400 +000"
The same applies to Linux environment. Just modifies the path of rotatelog
Windows: |bin/rotatelogs.exe
Linux: bin/rotatelogs
To get more benefit from the features, I recommend organizing each project into an independent virtualhost instead of organizing it into a single virtualhost separated by folders.