httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexei Kosut <ako...@organic.com>
Subject Patch to mod_log_config
Date Sat, 03 Aug 1996 00:57:21 GMT
Here's a patch that adds some functionality to mod_log_config; stuff
that's useful:

1. %v and %p directives, for the name of the host and the port it runs on,
respectively.

2. The ability to do "%{format}t" and have "format" passed on to
strftime(), instead of using the CLF format. i.e. "%{%Y/%m/%d-%H:%M:%S}t"
produces "1996/08/02-17:39:51" (we use this format here at Organic).

3. a %T directive, which gives the length of the request, in seconds.

4. A special-case to %o to allow you to do %{"Content-type"}o

I think these are relatively useful (we use variants of them here), and
shouldn't break anything. I'd like, therefore, to commit them, if people
don't mind :)

Another issue this brings up is something we've discussed earlier,
removing mod_log_common and making mod_log_config the default logger for
Apache. They behave (as I understand it) exactly the same, and
mod_log_config provides greater functionality. It was originally
experimental, but people have been using it safely for months and months
now, with no problems. I see no reason not to make it the default logger
for Apache.

Anyhow, here's the patch:

Index: mod_log_config.c
===================================================================
RCS file: /export/home/cvs/apache/src/mod_log_config.c,v
retrieving revision 1.7
diff -c -r1.7 mod_log_config.c
*** mod_log_config.c	1996/06/27 01:23:26	1.7
--- mod_log_config.c	1996/08/03 00:43:41
***************
*** 59,75 ****
   * The argument to LogFormat is a string, which can include literal
   * characters copied into the log files, and '%' directives as follows:
   *
   * %...h:  remote host
   * %...l:  remote logname (from identd, if supplied)
!  * %...u:  remote user (from auth; may be bogus if return status (%s) is 401)
!  * %...t:  time, in common log format time format
   * %...r:  first line of request
   * %...s:  status.  For requests that got internally redirected, this
   *         is status of the *original* request --- %...>s for the last.
!  * %...b:  bytes sent.
!  * %...{Foobar}i:  The contents of Foobar: header line(s) in the request
!  *                 sent to the client.
!  * %...{Foobar}o:  The contents of Foobar: header line(s) in the reply.
   *
   * The '...' can be nothing at all (e.g. "%h %u %r %s %b"), or it can
   * indicate conditions for inclusion of the item (which will cause it
--- 59,80 ----
   * The argument to LogFormat is a string, which can include literal
   * characters copied into the log files, and '%' directives as follows:
   *
+  * %...b:  bytes sent.
   * %...h:  remote host
+  * %...{Foobar}i:  The contents of Foobar: header line(s) in the request
+  *                 sent to the client.
   * %...l:  remote logname (from identd, if supplied)
!  * %...{Foobar}o:  The contents of Foobar: header line(s) in the reply.
!  * %...p:  the port the request was served to
   * %...r:  first line of request
   * %...s:  status.  For requests that got internally redirected, this
   *         is status of the *original* request --- %...>s for the last.
!  * %...t:  time, in common log format time format
!  * %...{format}t:  The time, in the form given by format, which should
!  *                 be in strftime(3) format.
!  * %...T:  the time taken to serve the request, in seconds.
!  * %...u:  remote user (from auth; may be bogus if return status (%s) is 401)
!  * %...v:  the name of the server (i.e. which virtual host?)
   *
   * The '...' can be nothing at all (e.g. "%h %u %r %s %b"), or it can
   * indicate conditions for inclusion of the item (which will cause it
***************
*** 94,115 ****
   * server.  If it doesn't have its own TransferLog, it writes to the
   * same descriptor (meaning the same process for "| ...").
   *
-  * That means that you can do things like:
-  *
-  * <VirtualHost hosta.com>
-  * LogFormat "hosta ..."
-  * ...
-  * </VirtualHost>
-  *
-  * <VirtualHost hosta.com>
-  * LogFormat "hostb ..."
-  * ...
-  * </VirtualHost>
-  *
-  * ... to have different virtual servers write into the same log file,
-  * but have some indication which host they came from, though a %v
-  * directive may well be a better way to handle this.
-  *
   * --- rst */
  
  #define DEFAULT_LOG_FORMAT "%h %l %u %t \"%r\" %s %b"
--- 99,104 ----
***************
*** 197,202 ****
--- 186,193 ----
  char *log_header_out (request_rec *r, char *a)
  {
      char *cp = table_get (r->headers_out, a);
+     if (!strcasecmp(a, "Content-type") && r->content_type)
+ 	cp = r->content_type;
      if (cp) return cp;
      return table_get (r->err_headers_out, a);
  }
***************
*** 208,228 ****
  {
      long timz;
      struct tm *t;
!     char tstr[MAX_STRING_LEN],sign;
      
      t = get_gmtoff(&timz);
-     sign = (timz < 0 ? '-' : '+');
-     if(timz < 0) 
-         timz = -timz;
- 
-     strftime(tstr,MAX_STRING_LEN,"[%d/%b/%Y:%H:%M:%S ",t);
  
!     sprintf (tstr + strlen(tstr), "%c%02ld%02ld]",
! 	     sign, timz/3600, timz%3600);
  
      return pstrdup (r->pool, tstr);
  }
  
  /*****************************************************************
   *
   * Parsing the log format string
--- 199,241 ----
  {
      long timz;
      struct tm *t;
!     char tstr[MAX_STRING_LEN];
      
      t = get_gmtoff(&timz);
  
!     if (a && *a) /* Custom format */
! 	strftime(tstr, MAX_STRING_LEN, a, t);
!     else { /* CLF format */
! 	char sign = (timz < 0 ? '-' : '+');
! 
! 	if(timz < 0) timz = -timz;
! 
! 	strftime(tstr,MAX_STRING_LEN,"[%d/%b/%Y:%H:%M:%S ",t);
! 	sprintf (tstr + strlen(tstr), "%c%02ld%02ld]",
! 		 sign, timz/3600, timz%3600);
!     }
  
      return pstrdup (r->pool, tstr);
  }
  
+ char *log_request_duration (request_rec *r, char *a) {
+     char duration[22];	/* Long enough for 2^64 */
+ 
+     sprintf(duration, "%ld", time(NULL) - r->request_time);
+     return pstrdup(r->pool, duration);
+ }
+ 
+ char *log_virtual_host (request_rec *r, char *a) {
+     return pstrdup(r->pool, r->server->server_hostname);
+ }
+ 
+ char *log_server_port (request_rec *r, char *a) {
+     char portnum[10];
+ 
+     sprintf(portnum, "%d", r->server->port);
+     return pstrdup(r->pool, portnum);
+ }
+ 
  /*****************************************************************
   *
   * Parsing the log format string
***************
*** 237,248 ****
--- 250,264 ----
      { 'l', log_remote_logname, 0 },
      { 'u', log_remote_user, 0 },
      { 't', log_request_time, 0 },
+     { 'T', log_request_duration, 0 },
      { 'r', log_request_line, 1 },
      { 's', log_status, 1 },
      { 'b', log_bytes_sent, 0 },
      { 'i', log_header_in, 0 },
      { 'o', log_header_out, 0 },
      { 'e', log_env_var, 0 },
+     { 'v', log_virtual_host, 0 },
+     { 'p', log_server_port, 0 },
      { '\0' }
  };
  


-- Alexei Kosut <akosut@organic.com>            The Apache HTTP Server 
   http://www.nueva.pvt.k12.ca.us/~akosut/      http://www.apache.org/


Mime
View raw message