httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Glenn <gs-apache-...@gluelogic.com>
Subject Re: [PATCH] ErrorLogsWithVhost for Apache 1.3.28
Date Tue, 08 Jul 2003 04:41:09 GMT
On Thu, Jun 26, 2003 at 11:18:41AM -0400, Glenn wrote:
> On Thu, Jun 26, 2003 at 09:01:21AM +0200, Astrid Ke?ler wrote:
> > What about a second parameter to ErrorLog?
> 
> That's an interesting idea.
> I can change ErrorLog to a TAKE12 to take an optional parameter so as not
> to break existing configs.  Is this method preferred to a second directive?
> 
> I am not suggesting supporting everything in LogFormat; only a few key
> words.  Initially, there would only be two key words for error log format,
> default and withvhost, or something like that.
> 
> I'd still rather set a global variable for withvhosts than to extend any
> existing structures, but would like to know if there are other cleaner
> methods.

With the talk about a minor MMN bump, I put together this patch which
adds a flag at the end of server_rec.  This also changes ErrorLog to
a TAKE12, with an optional style of "default" or "vhosts", where the
"vhosts" includes the server name and port in the error log entries.
The TAKE12 maintains backwards compatibility to existing config files.

Comments appreciated on the method(s) that would most likely get this
accepted into 1.3.28 or 1.3.29.  (global flag, server_rec addition,
other ...)  Thanks!

-Glenn


diff -ru apache_1.3.27/src/include/httpd.h apache_1.3.27.new/src/include/httpd.h
--- apache_1.3.27/src/include/httpd.h	2002-09-30 12:35:21.000000000 -0400
+++ apache_1.3.27.new/src/include/httpd.h	2003-07-07 19:12:08.000000000 -0400
@@ -966,8 +966,13 @@
     int limit_req_line;      /* limit on size of the HTTP request line    */
     int limit_req_fieldsize; /* limit on size of any request header field */
     int limit_req_fields;    /* limit on number of request header fields  */
+
+    int error_format_style;  /* format style of error log entries */
 };
 
+/* error format styles for log entry layout */
+enum { ERRORLOG_DEFAULT_STYLE = 0, ERRORLOG_WITH_VHOSTS = 1 };
+
 /* These are more like real hosts than virtual hosts */
 struct listen_rec {
     listen_rec *next;
diff -ru apache_1.3.27/src/main/http_core.c apache_1.3.27.new/src/main/http_core.c
--- apache_1.3.27/src/main/http_core.c	2002-09-30 12:35:21.000000000 -0400
+++ apache_1.3.27.new/src/main/http_core.c	2003-07-07 19:38:11.000000000 -0400
@@ -2063,6 +2063,35 @@
     return NULL;
 }
 
+static const char *set_error_log(cmd_parms *cmd, void *dummy,
+				 char *arg1, char *arg2)
+{
+    const char *err = ap_check_cmd_context(cmd,
+					   NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
+    if (err != NULL) {
+	return err;
+    }
+
+    if (arg2 == NULL) {
+	cmd->server->error_format_style = ERRORLOG_DEFAULT_STYLE;
+	cmd->server->error_fname = arg1;
+    }
+    else {
+	cmd->server->error_fname = arg2;
+	if (strcmp(arg1, "vhosts") == 0) {
+	    cmd->server->error_format_style = ERRORLOG_WITH_VHOSTS;
+	}
+	else if (strcmp(arg1, "default") == 0) {
+	    cmd->server->error_format_style = ERRORLOG_DEFAULT_STYLE;
+	}
+	else {
+	    return "invalid ErrorLog syntax";
+	}
+    }
+
+    return NULL;
+}
+
 static const char *set_send_buffer_size(cmd_parms *cmd, void *dummy, char *arg)
 {
     int s = atoi(arg);
@@ -3305,9 +3334,8 @@
   "En-/disable server signature (on|off|email)" },
 { "ServerRoot", set_server_root, NULL, RSRC_CONF, TAKE1,
   "Common directory of server-related files (logs, confs, etc.)" },
-{ "ErrorLog", set_server_string_slot,
-  (void *)XtOffsetOf (server_rec, error_fname), RSRC_CONF, TAKE1,
-  "The filename of the error log" },
+{ "ErrorLog", set_error_log, NULL, RSRC_CONF, TAKE12,
+  "The log style tag (default|vhosts) and filename of the error log" },
 { "PidFile", set_pidfile, NULL, RSRC_CONF, TAKE1,
     "A file for logging the server process ID"},
 { "ScoreBoardFile", set_scoreboard, NULL, RSRC_CONF, TAKE1,
diff -ru apache_1.3.27/src/main/http_log.c apache_1.3.27.new/src/main/http_log.c
--- apache_1.3.27/src/main/http_log.c	2002-05-19 00:55:38.000000000 -0400
+++ apache_1.3.27.new/src/main/http_log.c	2003-07-07 19:43:44.000000000 -0400
@@ -388,8 +388,15 @@
 	 * quad is the most secure, which is why I'm implementing it
 	 * first. -djg
 	 */
-	len += ap_snprintf(errstr + len, sizeof(errstr) - len,
-		"[client %s] ", r->connection->remote_ip);
+	if (r->server && r->server->error_format_style == ERRORLOG_WITH_VHOSTS){
+	    len += ap_snprintf(errstr + len, sizeof(errstr) - len,
+		    "[client %s] [%s:%d] ", r->connection->remote_ip,
+		    r->server->server_hostname, r->server->port);
+	}
+	else { /* no r->server or error_format_style == ERRORLOG_DEFAULT_STYLE*/
+	    len += ap_snprintf(errstr + len, sizeof(errstr) - len,
+		    "[client %s] ", r->connection->remote_ip);
+	}
     }
     if (!(level & APLOG_NOERRNO)
 	&& (save_errno != 0)

Mime
View raw message