httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@decus.org (Rodent of Unusual Size)
Subject [PATCH] to allow naming of logfile formats
Date Tue, 19 Aug 1997 11:48:45 GMT
>From the fingers of Marc Slemko flowed the following:
>
>Oh, something else that would be cool is magic words for CustomLog, eg.
>CLF, ECLF, etc.

    Now you've done it.  I think the attached patch does this for you.
    It adds a directive (settle down, Dean!):

     DefineLogFormat myformat "Private format: \"%r\""

    It basically just records the name/format pair in a table.  Then
    CustomLog can say

     CustomLog /tmp/logfile MyFormat
     CustomLog /tmp/log2 "Other format: \"%h\""

    CustomLog looks up the second argument in the table; if found, it
    substitutes the value - otherwise it uses the argument verbatim.
    Obviously the format-name isn't case-sensitive.  The format-name CLF
    is predefined.

    With this to shorten things, I feel better about adding a
    conditional to the end of the line, a la Dean's envariable checking.
    But I won't proceed with that until this is voted in..

    #ken    :-)}

Index: mod_log_config.c
===================================================================
RCS file: /export/home/cvs/apachen/src/modules/standard/mod_log_config.c,v
retrieving revision 1.35
diff -u -r1.35 mod_log_config.c
--- mod_log_config.c	1997/08/18 13:12:14	1.35
+++ mod_log_config.c	1997/08/19 11:54:12
@@ -192,6 +192,7 @@
   array_header *default_format;
   array_header *config_logs;    
   array_header *server_config_logs;
+  table *formats;
 } multi_log_state;
 
 /*
@@ -602,13 +603,16 @@
 	make_array(p, 5, sizeof (config_log_state));
     mls->default_format = NULL;
     mls->server_config_logs = NULL;
+    mls->formats = make_table(p, 4);
+    table_set(mls->formats, "CLF", DEFAULT_LOG_FORMAT);
     
     return mls;
 }
 
 /*
  * Use the merger to simply add a pointer from the vhost log state
- * to the log of logs specified for the non-vhost configuration
+ * to the log of logs specified for the non-vhost configuration.  Make sure
+ * vhosts inherit any globally-defined format names.
  */
 
 static void *merge_config_log_state (pool *p, void *basev, void *addv)
@@ -617,35 +621,64 @@
     multi_log_state *add = (multi_log_state *)addv;
     
     add->server_config_logs = base->config_logs;
-    if (!add->default_format)
+    if (!add->default_format) {
         add->default_format = base->default_format;
+    }
+    add->formats = overlay_tables(p, base->formats, add->formats);
     
     return add;
 }
 
+/*
+ * Define a name (such as CLF) for a specific log format.
+ */
+static const char *make_log_format(cmd_parms *cmd, void *mconfig,
+				   char *format_name, char *format_text)
+{
+    const char *parse_error = NULL;
+    char *parsed_format;
+    multi_log_state *mls = get_module_config (cmd->server->module_config,
+					      &config_log_module);
+
+    parse_log_string(cmd->pool, format_text, &parse_error);
+    if (parse_error == NULL) {
+	table_set(mls->formats, format_name, format_text);
+    };
+    return parse_error;
+}
+
 static const char *log_format (cmd_parms *cmd, void *dummy, char *arg)
 {
     const char *err_string = NULL;
+    char *format;
     multi_log_state *mls = get_module_config (cmd->server->module_config,
-					       &config_log_module);
-  
-    mls->default_format = parse_log_string (cmd->pool, arg, &err_string);
+					      &config_log_module);
+
+    format = table_get(mls->formats, arg);
+    format = (format != NULL) ? format : arg;
+    mls->default_format = parse_log_string (cmd->pool, format, &err_string);
     return err_string;
 }
 
-static const char *add_custom_log(cmd_parms *cmd, void *dummy, char *fn, char *fmt)
+static const char *add_custom_log(cmd_parms *cmd, void *dummy, char *fn,
+				  char *fmt) 
 {
     const char *err_string = NULL;
     multi_log_state *mls = get_module_config (cmd->server->module_config,
 					      &config_log_module);
     config_log_state *cls;
+    char *format;
 
     cls = (config_log_state*)push_array(mls->config_logs);
     cls->fname = fn;
-    if (!fmt)
+    if (!fmt) {
 	cls->format = NULL;
-    else
-	cls->format = parse_log_string (cmd->pool, fmt, &err_string);
+    }
+    else {
+	format = table_get(mls->formats, fmt);
+	format = (format != NULL) ? format : fmt;
+	cls->format = parse_log_string (cmd->pool, format, &err_string);
+    }
     cls->log_fd = -1;
     
     return err_string;
@@ -663,11 +696,13 @@
 
 static command_rec config_log_cmds[] = {
 { "CustomLog", add_custom_log, NULL, RSRC_CONF, TAKE2,
-    "a file name and a custom log format string" },
+    "a file name and a custom log format string or format name" },
 { "TransferLog", set_transfer_log, NULL, RSRC_CONF, TAKE1,
     "the filename of the access log" },
 { "LogFormat", log_format, NULL, RSRC_CONF, TAKE1,
     "a log format string (see docs)" },
+{ "DefineLogFormat", make_log_format, NULL, RSRC_CONF, TAKE2,
+    "a name and a log format string (see docs)" },
 { "CookieLog", set_cookie_log, NULL, RSRC_CONF, TAKE1,
     "the filename of the cookie log" },
 { NULL }

Mime
View raw message