Dynamic Log Filename in httpd.conf

Discussion in 'Apache' started by komodo, Oct 11, 2008.

  1. #1
    Hi,

    I run a cluster of 6 apache servers that share a common httpd.conf (through nfs). The problem I'm facing is with the log files.

    I do not want each server to store the log file on their own hard drives because of space restrictions, and I instead require the log files to be on the NFS mount (located at /array/).

    All six servers are writing to the log files at the same time, causing spliced lines and nearly unreadable output. My question is regarding this line:

    CustomLog /array/log/httpd-access.log combined

    Is there any way to save the log file to a dynamic path, such as:

    CustomLog /array/log/__$LOCAL_HOST_NAME$__/httpd-access.log

    Or even better, does anyone have any ideas on how to keep a single log file for all servers, without splicing and mutilating the output, and without slowing down each server, waiting for locks on the file to release?

    I look forward to your help. Thanks in advance. :)
     
    komodo, Oct 11, 2008 IP
  2. komodo

    komodo Well-Known Member

    Messages:
    379
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    123
    #2
    Anyone? I'd really appreciate some tips.

    Thanks. :)
     
    komodo, Oct 13, 2008 IP
  3. Ladadadada

    Ladadadada Peon

    Messages:
    382
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Having multiple processes writing to a single file gets very messy very quickly. It gets even messier when it is being done over NFS because file locking with NFS is not very good.

    I would recommend having each of your web servers writing to a separate file and combining them all later on. You could write a simple script that could read in all the files and output one single file with all the lines in the correct order.

    I don't think Apache has the ability to use variables in a single conf file but it does have the ability to save the log files to a pipe.
    CustomLog "| /array/scripts/logfile_splitter.sh /array/log/__$LOCAL_HOST_NAME$__/httpd-access.log" combined
    Code (markup):
    The logfile_splitter.sh script will need to take one argument which is a path to the logfile it should create. It should replace the placeholder with the name of the webserver it is on. After that, all it needs to do is read from stdin and write to the log file.
     
    Ladadadada, Oct 14, 2008 IP