MKSA
MKSA

Reputation: 45

Apache Alias with a log file

I would like to know if it is possible to create an Alias with a log on it on a virtual host in Apache?

This is what I have so far:

<VirtualHost www.mycompany.com>
    ServerName www.mycompany.com
    DirectoryIndex Company_Home.html
    ServerAdmin [email protected]
    DocumentRoot C:/Project/Sites/Company/Main/htdocs
    ErrorLog C:/Project/Sites/Company/Main/logs/Error_log.log
    TransferLog C:/Project/Sites/Company/Main/logs/Access_log.log
    Alias /public C:/Project/Sites/Company/Sub/Public/htdocs/Public.html
    Alias /stage C:/Project/Sites/Company/Sub/Stage/htdocs/Stage.html
    Alias /development C:/Project/Sites/Company/Sub/Development/htdocs/Development.html

I want to create an Access and Error Log on all 3 aliases.

Upvotes: 4

Views: 4745

Answers (1)

SirDarius
SirDarius

Reputation: 42899

It is not possible using a filename, because both directives ErrorLog and TransferLog are server or virtual host level, and cannot therefore be specified for specific alias.

However, you can probably obtain the desired behaviour by using a process into which the logs will be piped to by apache, for example:

ErrorLog |C:/Project/Sites/Company/error_logger.exe
TransferLog |C:/Project/Sites/Company/transfer_logger.exe

Each program will be started by apache and will receive the log lines on their standard input. You are free to do whatever you want with these strings in your programs.

The main problem to solve here is to force the log format to contain the alias information so your program can redirect the correct log lines to the corresponding file.

It is easy for the TransferLog to have this information, since it will be available as the leading part of the URL being logged (%U flag in the log format).

For the error log, it is much more difficult, probably impossible even, because various modules such as PHP can generate error messages that completely lack any URL information.

edit:

For the record, Apache 2.3.9 introduced a new directive ErrorLogFormat which allows a great deal of customization of error log lines, however, the %U flag is surprisingly not present, so it won't be helpful to you here.

Upvotes: 2

Related Questions