FastCGI tricks,,, keeping seperate log files for virtual hosts

yalcin Bozcaada (bozcaada@OpenMarket.com)
Mon, 14 Jul 1997 14:09:11 -0400

Message-Id: <01BC905F.87E9CA70@w1-139.openmarket.com>
From: yalcin Bozcaada <bozcaada@OpenMarket.com>
To: "fastcgi-developers@openmarket.com"
Subject: FastCGI tricks,,, keeping seperate log files for virtual hosts
Date: Mon, 14 Jul 1997 14:09:11 -0400

Hi,

Just a little suggestion for people who do virtual hosting and wanted to automate
their logging into seperate files for each host.

I did my work and tests using Open Market's SecureWebServer 2.0.x and 
fastcgi kit 1.5.1.

First, you don't want to duplicate the logging, so you can turn off logging in your
httpd.config file.

The trick is using an authorizer program and authorizing the region /* and letting
everything go. But, before you let the client request, go grab the virtual host name
or port and log it the way you want into another file.

Here is a main structure of the program:

char *VirtHost;
FILE *logfile;
FILE *A, *B;
/** your seperate log files for different hosts **/
A = fopen("A.com.log","a+");
B = fopen("B.com.log","a+");

while( FCGI_Accept() )
{
     VirtHost = getenv("SERVER_ADDR");
      if( strcmp(VirtHost,"111.222.000.1") == 0 ) logfile = A;
      else 
      if( strcmp(VirtHost,"111.222.000.2") == 0 ) logfile = B;
      ....
      ....
      /** 
         after determining which file to write to, fill into your own
         customized log file
      **/
      fprintf(logfile,"\r\nAccess by %s / URL = %s ",rmhost, urlpath );
      fflush(logfile);
      /** now let the server continue with the URL **/
      printf("Status: 200 OK\r\n" ...
}

fclose(A);
fclose(B);

Now, this program should run really fast. At least faster than the URLs that
go to the server most of the time. But, in case a broken pipe problem, the number
of FastCGI processes could be increased along with listener-queue-depth.

There is an annoying issue I came accross so far.  If a URL has been authorized
by another FastCGI authorizer and there is a redirect on success, that would be 
missed. I am trying to find a workaround for that too.


-yalcin