Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to set up Apache2 so that it logs to a separate log for access and error. App1 is located at /var/www/ and App2 is located at /var/www/app2. How should I approach this problem?

Should I create a virtual host for each directory or will a .htaccess work for what I am trying to do?

share|improve this question

2 Answers 2

Put the ErrorLog directive in the site configuration /etc/apache2/site-available/mysite :

CustomLog ${APACHE_LOG_DIR}/access.log
ErrorLog ${APACHE_LOG_DIR}/error.log

Eventually you can replace ${APACHE_LOG_DIR} with an absolute path.

If you want more complicated things, you can use the rotatelogs utility like:

CustomLog "|bin/rotatelogs logs/access.%Y-%m-%d-%H_%M_%S 10M" common
ErrorLog "|bin/rotatelogs logs/error.%Y-%m-%d-%H_%M_%S 10M"

While you're at it, you can specify an additional pre/postfix to "access/error" string to customise this per site.

share|improve this answer

An .htaccess file won't work, sorry. You need to put it in a logfile.

From the config docs at apache

CustomLog Directive
Description:    Sets filename and format of log file
Syntax: CustomLog file|pipe format|nickname [env=[!]environment-variable]
Context:    server config, virtual host
Status: Base
Module: mod_log_config

I haven't tested to see if it works in blocks though. You might want to experiment with that. Failing that, they have an example of SetEnfIf and CustomLog based on env vars which would work for what you wanted.

share|improve this answer
    
You mean config file, not logfile, I think? –  Jenny D Apr 24 '13 at 9:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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