Generate Apache logs in different files

Asked

Viewed 672 times

3

I have a VM running a single PHP project, only so far with external access released. Last week I needed to create a folder inside the www with the signatures of the employees' emails, and the log file at that time is full, because in every email received from here it saves in the Apache log:

inserir a descrição da imagem aqui

Is there any way to "split" the Apache log, one for each project in the WWW folder? Or even disable the log for the "Signatures" project"?

Update: Apache Version

inserir a descrição da imagem aqui

1 answer

2

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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.