This adds a directive ErrorLogsWithVhost that extends the error log format
by adding server name and port to entries in the error logs.
Proof of concept.  Are there better ways to do this than using a global?

Cheers,
Glenn

diff -ru apache_1.3.27/src/include/http_conf_globals.h 
apache_1.3.27.new/src/include/http_conf_globals.h
--- apache_1.3.27/src/include/http_conf_globals.h       2002-09-27 13:40:24.000000000 
-0400
+++ apache_1.3.27.new/src/include/http_conf_globals.h   2003-05-28 01:21:42.000000000 
-0400
@@ -90,6 +90,7 @@
 extern API_VAR_EXPORT int ap_daemons_limit;
 extern API_VAR_EXPORT int ap_suexec_enabled;
 extern API_VAR_EXPORT int ap_listenbacklog;
+extern int ap_error_logs_with_vhost;
 #ifdef SO_ACCEPTFILTER
 extern int ap_acceptfilter;
 #endif
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-05-28 01:23:07.000000000 -0400
@@ -2063,6 +2063,18 @@
     return NULL;
 }
 
+static const char *set_error_logs_with_vhost(cmd_parms *cmd, void *dummy)
+{
+    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
+    if (err != NULL) {
+        return err;
+    }
+
+    ap_error_logs_with_vhost = 1;
+    return NULL;
+}
+
+
 static const char *set_send_buffer_size(cmd_parms *cmd, void *dummy, char *arg)
 {
     int s = atoi(arg);
@@ -3308,6 +3320,8 @@
 { "ErrorLog", set_server_string_slot,
   (void *)XtOffsetOf (server_rec, error_fname), RSRC_CONF, TAKE1,
   "The filename of the error log" },
+{ "ErrorLogsWithVhost", set_error_logs_with_vhost, NULL, RSRC_CONF, NO_ARGS,
+  "Include the virtual host and port, if available, in error log entries" },
 { "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-05-28 01:24:38.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 (ap_error_logs_with_vhost && r->server) {
+           len += ap_snprintf(errstr + len, sizeof(errstr) - len,
+                   "[client %s] [%s:%d] ", r->connection->remote_ip,
+                   r->server->server_hostname, r->server->port);
+       }
+       else {
+           len += ap_snprintf(errstr + len, sizeof(errstr) - len,
+                   "[client %s] ", r->connection->remote_ip);
+       }
     }
     if (!(level & APLOG_NOERRNO)
        && (save_errno != 0)
diff -ru apache_1.3.27/src/main/http_main.c apache_1.3.27.new/src/main/http_main.c
--- apache_1.3.27/src/main/http_main.c  2002-09-27 13:40:24.000000000 -0400
+++ apache_1.3.27.new/src/main/http_main.c      2003-05-28 01:22:09.000000000 -0400
@@ -257,6 +257,7 @@
 API_VAR_EXPORT time_t ap_restart_time=0;
 API_VAR_EXPORT int ap_suexec_enabled = 0;
 API_VAR_EXPORT int ap_listenbacklog=0;
+int ap_error_logs_with_vhost=0;
 
 struct accept_mutex_methods_s {
     void (*child_init)(pool *p);

Reply via email to