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] Cleaning up FILE,LINE,errno in aplog_error()
Date Wed, 01 Oct 1997 19:55:09 GMT
    I spent a little time on this to-day to try to address the issues of
    filename, line number, and errno information showing up in the error
    log.

    The solution I present here has the advantage that it won't change
    any of the exiting message until the corresponding aplog_error()
    calls are altered.

    The solution I have here is to add a Boolean argument to
    aplog_error() to indicate whether errno information should be
    included.  Also, if the filename is NULL or the line number is -,
    those fields won't be included.  Finally, the following macros to
    control the behaviour have been added: APLOG_NOMARK,
    APLOG_MARK_NOERRNO, and APLOG_NOMARK_NOERRNO.

    I've also added a patch for mod_unique_id.c that demonstrates the
    use.

    Hopefully this will address some of the issues with logging before
    1.3b1..

    #ken    P-)}

Index: main/http_log.h
===================================================================
RCS file: /export/home/cvs/apachen/src/main/http_log.h,v
retrieving revision 1.13
diff -u -w -r1.13 http_log.h
--- http_log.h	1997/09/12 20:13:08	1.13
+++ http_log.h	1997/10/01 20:10:49
@@ -59,7 +59,10 @@
 #define	APLOG_INFO	6	/* informational */
 #define	APLOG_DEBUG	7	/* debug-level messages */
 #define DEFAULT_LOGLEVEL	APLOG_ERR
-#define APLOG_MARK	__FILE__,__LINE__
+#define APLOG_MARK      __FILE__,__LINE__,1
+#define APLOG_MARK_NOERRNO __FILE__,__LINE__,0
+#define APLOG_NOMARK    NULL,0,1
+#define APLOG_NOMARK_NOERRNO NULL,0,0
 
 typedef struct _trans {
 	char	*t_name;
@@ -67,8 +70,9 @@
 } TRANS;
 
 void open_logs (server_rec *, pool *p);
-API_EXPORT(void) aplog_error(const char *file, int line, int level,
-			     const server_rec *s, const char *fmt, ...);
+API_EXPORT(void) aplog_error(const char *file, int line, int incl_errno,
+                             int level, const server_rec *s, 
+                             const char *fmt, ...);
 API_EXPORT(void) error_log2stderr (server_rec *);     
 
 void log_pid (pool *p, char *fname);
Index: main/http_log.c
===================================================================
RCS file: /export/home/cvs/apachen/src/main/http_log.c,v
retrieving revision 1.34
diff -u -w -r1.34 http_log.c
--- http_log.c	1997/09/12 20:37:33	1.34
+++ http_log.c	1997/10/01 20:10:54
@@ -247,27 +247,49 @@
         dup2(fileno(s->error_log),STDERR_FILENO);
 }
 
-API_EXPORT(void) aplog_error (const char *file, int line, int level,
-			      const server_rec *s, const char *fmt, ...)
+API_EXPORT(void) aplog_error (const char *file, int line, int incl_errno,
+                              int level, const server_rec *s,
+                              const char *fmt, ...)
 {
     va_list args;
     char errstr[MAX_STRING_LEN];
+    char fstr[48];
+    char serrno[48], sline[48];
+    char *p_file, *p_line, *p_errno;
+    const char *fname;
     static TRANS *pname = priorities;
     
 
-    if (level > s->loglevel)
+    if (level > s->loglevel) {
 	return;
+    }
+
+    ap_snprintf(serrno, sizeof(serrno), "%d", errno);
+    ap_snprintf(sline, sizeof(sline), "%d", line);
+    p_errno = (incl_errno) ? "%s: %s: " : "%.0s%.0s";
+    p_line = (line != 0) ? "%s: " : "%.0s";
+    if (file == NULL) {
+        p_file = "%.0s";
+        fname = "";
+    }
+    else {
+        p_file = "%s: ";
+        fname = file;
+    }
 
     switch (s->loglevel) {
     case APLOG_DEBUG:
-	ap_snprintf(errstr, sizeof(errstr), "[%s] %d: %s: %s: %d: ",
-		    pname[level].t_name, errno, strerror(errno), file, line);
+        ap_snprintf(fstr, sizeof(fstr), "[%%s] %s%s%s", p_errno, p_file,
+                    p_line);
+        ap_snprintf(errstr, sizeof(errstr), fstr,
+                    pname[level].t_name, serrno, strerror(errno), fname, sline);
 	break;
     case APLOG_EMERG:
     case APLOG_CRIT:
     case APLOG_ALERT:
-	ap_snprintf(errstr, sizeof(errstr), "[%s] %d: %s: ",
-		    pname[level].t_name, errno, strerror(errno));
+        ap_snprintf(fstr, sizeof(fstr), "[%%s] %s", p_errno);
+        ap_snprintf(errstr, sizeof(errstr), fstr,
+                    pname[level].t_name, serrno, strerror(errno));
 	break;
     case APLOG_INFO:
     case APLOG_ERR:
@@ -319,7 +341,7 @@
 API_EXPORT(void) log_unixerr (const char *routine, const char *file,
 			      const char *msg, server_rec *s)
 {
-    aplog_error(file, 0, APLOG_ERR, s, msg);
+    aplog_error(file, 0, 1, APLOG_ERR, s, msg);
 }
 
 API_EXPORT(void) log_printf (const server_rec *s, const char *fmt, ...)
Index: modules/standard/mod_unique_id.c
===================================================================
RCS file: /export/home/cvs/apachen/src/modules/standard/mod_unique_id.c,v
retrieving revision 1.4
diff -u -w -r1.4 mod_unique_id.c
--- mod_unique_id.c	1997/09/16 04:49:50	1.4
+++ mod_unique_id.c	1997/10/01 20:10:58
@@ -145,7 +145,7 @@
      */
     if (XtOffsetOf(unique_id_rec, counter) + sizeof(cur_unique_id.counter)
         != 14) {
-        aplog_error(APLOG_MARK, APLOG_ALERT, s,
+        aplog_error(APLOG_MARK_NOERRNO, APLOG_ALERT, s,
                     "mod_unique_id: sorry the size assumptions are wrong "
                     "in mod_unique_id.c, please remove it from your server "
                     "or fix the code!");
@@ -158,7 +158,7 @@
      * be unique as the physical address of the machine
      */
     if (gethostname(str, sizeof(str) - 1) != 0) {
-        aplog_error(APLOG_MARK, APLOG_ALERT, s,
+        aplog_error(APLOG_MARK_NOERRNO, APLOG_ALERT, s,
           "gethostname: mod_unique_id requires the hostname of the server");
         exit(1);
     }
@@ -171,7 +171,7 @@
 
     global_in_addr = ((struct in_addr *) hent->h_addr_list[0])->s_addr;
 
-    aplog_error(APLOG_MARK, APLOG_INFO, s,
+    aplog_error(APLOG_NOMARK_NOERRNO, APLOG_INFO, s,
                 "mod_unique_id: using ip addr %s",
                 inet_ntoa(*(struct in_addr *) hent->h_addr_list[0]));
 

Mime
View raw message