1

I stuck with this issue, googled it around and got some solutions but unlikely it is not working properly. Can anyone give a solution for this please,

I'm running Apache2 in Ubuntu 14.04 machine. Have only one virtual host running in it and have a document root under /var/www/html where our resides.

Inside html directory our code contains sub-directories. For eg. dir1, dir2. I need the error log should be customized like all the error log related to code under dir1 should resides inside dir1 and same for dir2.

How I can customize the error logs?

  • Why not separate them in 2 different virtual hosts? – Dan Aug 31 '17 at 7:20
  • No. Customer don't want us to do that Dan! – harsha Aug 31 '17 at 7:22
1

According this post https://stackoverflow.com/questions/10395043/apache-server-multiple-directories-different-error-logs

It is not doable for the error log as ErrorLog directive works only in server config or virtual host context. It is possible to separate AccessLog with features provided by setenvif module.

Alternatively one can try something like that:

ErrorLog "|/usr/bin/tee -a ${APACHE_LOG_DIR}/error.log /var/www/apachelogs/error.txt"

Just put more sophisticated filtering script in between and may be you manage to achieve what you need.

Some nitpicking, why would you need error log in the directory with code ? Imho it is a security threat.

  • Thanks mestia. The solution which you have suggested, I guess it will not separate the logs based on directories. We need this because each developers are working on different directory (code ). They want to know whats the error they are getting particularly for the code which they are working on. – harsha Aug 31 '17 at 7:12
  • In this case I guess you can set a variable with setenvif and place this variable to the error log file by adjusting the error log directive and adding logging of %{VARNAME}e. is this works just filter the corresponding values before giving them to the developers. – mestia Aug 31 '17 at 7:28
0

I believe this is what you want:

SetEnvIf Request_URI ^/app/subapp1(/|$) subapp1
SetEnvIf Request_URI ^/app/subapp2(/|$) subapp2

CustomLog /absolute/path/to/app/subapp1/log/access_log common env=subapp1
CustomLog /absolute/path/to/app/subapp2/log/access_log common env=subapp2

Source:

https://stackoverflow.com/questions/1460757/generate-access-logs-for-different-subdirectories-in-apache

  • Thanks for the reply George. I already tried this solution, it is working for access_logs but not for error.logs. – harsha Aug 31 '17 at 6:53
  • Even when you edit the name to ErrorLog? – George Udosen Aug 31 '17 at 6:56
  • Please see this: stackoverflow.com/questions/10395043/… – George Udosen Aug 31 '17 at 7:05
  • CustomLog /var/www/html/app1/error.log env=app1 ErrorLog /var/www/html/app1/error.log CustomLog /var/www/html/app2/error.log env=app2 ErrorLog /var/www/html/app2/error.log This is how I edited for error.log. Is it correct? – harsha Aug 31 '17 at 7:05
  • I tried even that, I got this error AH00526: Syntax error on line 50 of /etc/apache2/sites-enabled/000-default.conf: ErrorLog takes one argument, The filename of the error log – harsha Aug 31 '17 at 7:14
0

Simply use in your vhost

ErrorLog error.log

and it will write error file in the same folder in which the script causing the error resides.

An error in

http://example.com/some/dir/test.php

will write the error in

/public_html/some/dir/error.log

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.