Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .