You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Randy Terbush <ra...@zyzzyva.com> on 1997/06/22 05:26:28 UTC

[PATCH] Loglevels and logging routine consolidation

This is one of those features that has been on the want list for 
some time. This is a rough cut with only changes for log_error from
http_main.c included. I'd appreciate some comments before I go 
further. 

I've scrapped log_unixerr() and log_printf() in favor of a log_error 
that accepts variable arguments. Levels assigned to these errors is 
up for debate.

Should this be a per/dir config item?

Index: http_core.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_core.c,v
retrieving revision 1.84
diff -c -c -r1.84 http_core.c
*** http_core.c	1997/06/17 00:09:13	1.84
--- http_core.c	1997/06/22 03:19:30
***************
*** 1156,1161 ****
--- 1156,1167 ----
      return NULL;
  }
  
+ const char *set_loglevel(cmd_parms *cmd, void *dummy, int level)
+ {
+     cmd->server->loglevel = level;
+     return NULL;
+ }
+ 
  /* Note --- ErrorDocument will now work from .htaccess files.  
   * The AllowOverride of Fileinfo allows webmasters to turn it off
   */
***************
*** 1212,1217 ****
--- 1218,1224 ----
  { "ErrorLog", set_server_string_slot,
    (void *)XtOffsetOf (server_rec, error_fname), RSRC_CONF, TAKE1,
    "The filename of the error log" },
+ { "LogLevel", set_loglevel, NULL, RSRC_CONF, TAKE1, "Level of logging verbosity"},
  { "PidFile", set_pidfile, NULL, RSRC_CONF, TAKE1,
      "A file for logging the server process ID"},
  { "ScoreBoardFile", set_scoreboard, NULL, RSRC_CONF, TAKE1,
Index: http_log.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_log.c,v
retrieving revision 1.14
diff -c -c -r1.14 http_log.c
*** http_log.c	1997/06/15 19:22:25	1.14
--- http_log.c	1997/06/22 03:19:35
***************
*** 158,191 ****
      fclose(pid_file);
  }
  
! void log_error(char *err, server_rec *s) {
!     fprintf(s->error_log, "[%s] %s\n",get_time(),err);
!     fflush(s->error_log);
! }
! 
! void
! log_unixerr(const char *routine, const char *file, const char *msg,
! 	    server_rec *s)
! {
!     const char *p, *q;
! 
!     p = strerror(errno);
!     q = get_time();
! 
!     if (file != NULL)
! 	fprintf(s->error_log, "[%s] %s: %s: %s\n", q, routine, file, p);
!     else
! 	fprintf(s->error_log, "[%s] %s: %s\n", q, routine, p);
!     if (msg != NULL) fprintf(s->error_log, "[%s] - %s\n", q, msg);
! 
!     fflush(s->error_log);
! }
! 
! void
! log_printf(const server_rec *s, const char *fmt, ...)
  {
      va_list args;
      
      fprintf(s->error_log, "[%s] ", get_time());
      va_start (args, fmt);
      vfprintf (s->error_log, fmt, args);
--- 158,169 ----
      fclose(pid_file);
  }
  
! void log_error(int level, const server_rec *s, const char *fmt, ...)
  {
      va_list args;
      
+     if (s->loglevel > level) return;
+     
      fprintf(s->error_log, "[%s] ", get_time());
      va_start (args, fmt);
      vfprintf (s->error_log, fmt, args);
***************
*** 195,201 ****
      fflush(s->error_log);
  }
  
! void log_reason(const char *reason, const char *file, request_rec *r) {
      fprintf (r->server->error_log,
  	     "[%s] access to %s failed for %s, reason: %s\n",
  	     get_time(), file,
--- 173,179 ----
      fflush(s->error_log);
  }
  
! void log_reason(int level, const char *reason, const char *file, request_rec *r) {
      fprintf (r->server->error_log,
  	     "[%s] access to %s failed for %s, reason: %s\n",
  	     get_time(), file,
Index: http_log.h
===================================================================
RCS file: /export/home/cvs/apache/src/http_log.h,v
retrieving revision 1.7
diff -c -c -r1.7 http_log.h
*** http_log.h	1997/01/01 18:10:19	1.7
--- http_log.h	1997/06/22 03:19:35
***************
*** 50,62 ****
   *
   */
  
  void open_logs (server_rec *, pool *p);
  void error_log2stderr (server_rec *);     
  
  void log_pid (pool *p, char *pid_fname);
! void log_error(char *err, server_rec *s);
! extern void log_unixerr(const char *routine, const char *file,
  			const char *msg, server_rec *s);
! void log_printf(const server_rec *s, const char *fmt, ...);
! void log_reason(const char *reason, const char *fname, request_rec *r);
  
--- 50,65 ----
   *
   */
  
+ #define APLOG_LEVEL1 1
+ #define APLOG_LEVEL2 2
+ #define APLOG_LEVEL3 3
+ 
  void open_logs (server_rec *, pool *p);
  void error_log2stderr (server_rec *);     
  
  void log_pid (pool *p, char *pid_fname);
! void log_error(int level, const server_rec *s, const char *fmt, ...);
! extern void log_unixerr(int level, const char *routine, const char *file,
  			const char *msg, server_rec *s);
! void log_reason(int level, const char *reason, const char *fname, request_rec *r);
  
Index: http_main.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_main.c,v
retrieving revision 1.157
diff -c -c -r1.157 http_main.c
*** http_main.c	1997/06/21 22:27:11	1.157
--- http_main.c	1997/06/22 03:20:00
***************
*** 258,265 ****
  	continue;
  
      if (ret < 0) {
! 	log_unixerr("fcntl", "F_SETLKW", "Error getting accept lock. Exiting!",
! 		    server_conf);
  	exit(1);
      }
  }
--- 258,266 ----
  	continue;
  
      if (ret < 0) {
! 	log_error(APLOG_LEVEL1, server_conf,
! 		  "%s: fcntl: F_SETLKW - Error getting accept lock. Exiting!",
! 		  strerror(errno));
  	exit(1);
      }
  }
***************
*** 268,275 ****
  {
      if (fcntl (lock_fd, F_SETLKW, &unlock_it) < 0)
      {
! 	log_unixerr("fcntl", "F_SETLKW", "Error freeing accept lock. Exiting!",
! 		    server_conf);
  	exit(1);
      }
  }
--- 269,277 ----
  {
      if (fcntl (lock_fd, F_SETLKW, &unlock_it) < 0)
      {
! 	log_error(APLOG_LEVEL1, server_conf,
! 		  "%s: fcntl: F_SETLKW - Error freeing accept lock. Exiting!",
! 		  strerror(errno));
  	exit(1);
      }
  }
***************
*** 313,320 ****
  	continue;
  
      if (ret < 0) {
! 	log_unixerr("flock", "LOCK_EX", "Error getting accept lock. Exiting!",
! 		    server_conf);
  	exit(1);
      }
  }
--- 315,323 ----
  	continue;
  
      if (ret < 0) {
! 	log_error(APLOG_LEVEL1, server_conf,
! 		  "%s: flock: LOCK_EX - Error getting accept lock. Exiting!",
! 		  strerror(errno));
  	exit(1);
      }
  }
***************
*** 323,330 ****
  {
      if (flock (lock_fd, LOCK_UN) < 0)
      {
! 	log_unixerr("flock", "LOCK_UN", "Error freeing accept lock. Exiting!",
! 		    server_conf);
  	exit(1);
      }
  }
--- 326,334 ----
  {
      if (flock (lock_fd, LOCK_UN) < 0)
      {
! 	log_error(APLOG_LEVEL1, server_conf,
! 		  "%s: flock: LOCK_UN - Error freeing accept lock. Exiting!",
! 		  strerror(errno));
  	exit(1);
      }
  }
***************
*** 411,418 ****
      }
      
      if (!current_conn->keptalive) 
!        log_error(errstr, current_conn->server);
!       
      if (timeout_req) {
  	/* Someone has asked for this transaction to just be aborted
  	 * if it times out...
--- 415,422 ----
      }
      
      if (!current_conn->keptalive) 
! 	log_error(APLOG_LEVEL3, current_conn->server, "%s", errstr);
!           
      if (timeout_req) {
  	/* Someone has asked for this transaction to just be aborted
  	 * if it times out...
***************
*** 616,622 ****
  
      if (setsockopt(s, SOL_SOCKET, SO_LINGER,
                     (char *)&li, sizeof(struct linger)) < 0) {
!         log_unixerr("setsockopt", "(SO_LINGER)", NULL, server_conf);
          /* not a fatal error */
      }
  }
--- 620,627 ----
  
      if (setsockopt(s, SOL_SOCKET, SO_LINGER,
                     (char *)&li, sizeof(struct linger)) < 0) {
!         log_error(APLOG_LEVEL2, server_conf,
! 		  "%s: setsockopt: (SO_LINGER)", strerror(errno));
          /* not a fatal error */
      }
  }
***************
*** 856,862 ****
      }
  
      ap_snprintf(errstr, sizeof(errstr), "created shared memory segment #%d", shmid);
!     log_error(errstr, server_conf);
  
  #ifdef MOVEBREAK
      /*
--- 861,867 ----
      }
  
      ap_snprintf(errstr, sizeof(errstr), "created shared memory segment #%d", shmid);
!     log_error(APLOG_LEVEL2, server_conf, "%s", errstr);
  
  #ifdef MOVEBREAK
      /*
***************
*** 908,914 ****
  	perror("shmctl");
  	fprintf(stderr, "httpd: Could not delete segment #%d\n", shmid);
  	ap_snprintf(errstr, sizeof(errstr), "could not remove shared memory segment #%d", shmid);
! 	log_unixerr("shmctl","IPC_RMID",errstr, server_conf);
      }
      if (scoreboard_image == BADSHMAT)	/* now bailout */
  	exit(1);
--- 913,921 ----
  	perror("shmctl");
  	fprintf(stderr, "httpd: Could not delete segment #%d\n", shmid);
  	ap_snprintf(errstr, sizeof(errstr), "could not remove shared memory segment #%d", shmid);
! 	log_error(APLOG_LEVEL1, server_conf,
! 		  "%s: shmctl: IPC_RMID - %s", strerror(errno), errstr);
! 	
      }
      if (scoreboard_image == BADSHMAT)	/* now bailout */
  	exit(1);
***************
*** 1379,1385 ****
  
  
  void sig_term() {
!     log_error("httpd: caught SIGTERM, shutting down", server_conf);
      cleanup_scoreboard();
  #ifdef SIGKILL
      ap_killpg (pgrp, SIGKILL);
--- 1386,1392 ----
  
  
  void sig_term() {
!     log_error(APLOG_LEVEL3, server_conf, "httpd: caught SIGTERM, shutting down");
      cleanup_scoreboard();
  #ifdef SIGKILL
      ap_killpg (pgrp, SIGKILL);
***************
*** 1398,1404 ****
  	    "httpd: caught SIGBUS, attempting to dump core in %s",
  	    server_root
  	);
!     log_error(emsg, server_conf);
      chdir(server_root);
      abort();         
      exit(1);
--- 1405,1411 ----
  	    "httpd: caught SIGBUS, attempting to dump core in %s",
  	    server_root
  	);
!     log_error(APLOG_LEVEL1, server_conf, emsg);
      chdir(server_root);
      abort();         
      exit(1);
***************
*** 1414,1420 ****
  	    "httpd: caught SIGSEGV, attempting to dump core in %s",
  	    server_root
  	);
!     log_error(emsg, server_conf);
      chdir(server_root);
      abort();
      exit(1);
--- 1421,1427 ----
  	    "httpd: caught SIGSEGV, attempting to dump core in %s",
  	    server_root
  	);
!     log_error(APLOG_LEVEL1, server_conf, emsg);
      chdir(server_root);
      abort();
      exit(1);
***************
*** 1459,1472 ****
      if (!one_process) {
  	sa.sa_handler = (void (*)())seg_fault;
  	if (sigaction (SIGSEGV, &sa, NULL) < 0)
! 	    log_unixerr ("sigaction(SIGSEGV)", NULL, NULL, server_conf);
  	sa.sa_handler = (void (*)())bus_error;
  	if (sigaction (SIGBUS, &sa, NULL) < 0)
! 	    log_unixerr ("sigaction(SIGBUS)", NULL, NULL, server_conf);
      }
      sa.sa_handler = (void (*)())sig_term;
      if (sigaction (SIGTERM, &sa, NULL) < 0)
! 	log_unixerr ("sigaction(SIGTERM)", NULL, NULL, server_conf);
  
      /* wait_or_timeout uses sleep() which could deliver a SIGALRM just as we're
       * trying to process the restart requests.  That's not good.  restart
--- 1466,1479 ----
      if (!one_process) {
  	sa.sa_handler = (void (*)())seg_fault;
  	if (sigaction (SIGSEGV, &sa, NULL) < 0)
! 	    log_error(APLOG_LEVEL1, server_conf, "%s: sigaction(SIGSEGV)", strerror(errno));
  	sa.sa_handler = (void (*)())bus_error;
  	if (sigaction (SIGBUS, &sa, NULL) < 0)
! 	    log_error(APLOG_LEVEL1, server_conf, "%s: sigaction(SIGBUS)", strerror(errno));
      }
      sa.sa_handler = (void (*)())sig_term;
      if (sigaction (SIGTERM, &sa, NULL) < 0)
! 	log_error(APLOG_LEVEL1, server_conf, "%s: sigaction(SIGTERM)", strerror(errno));
  
      /* wait_or_timeout uses sleep() which could deliver a SIGALRM just as we're
       * trying to process the restart requests.  That's not good.  restart
***************
*** 1482,1490 ****
      sigaddset (&sa.sa_mask, SIGUSR1);
      sa.sa_handler = (void (*)())restart;
      if (sigaction (SIGHUP, &sa, NULL) < 0)
! 	log_unixerr ("sigaction(SIGHUP)", NULL, NULL, server_conf);
      if (sigaction (SIGUSR1, &sa, NULL) < 0)
! 	log_unixerr ("sigaction(SIGUSR1)", NULL, NULL, server_conf);
  #else
      if(!one_process) {
  	signal (SIGSEGV, (void (*)(int))seg_fault);
--- 1489,1497 ----
      sigaddset (&sa.sa_mask, SIGUSR1);
      sa.sa_handler = (void (*)())restart;
      if (sigaction (SIGHUP, &sa, NULL) < 0)
! 	log_error(APLOG_LEVEL2, server_conf, "%s: sigaction(SIGHUP)", strerror(errno));
      if (sigaction (SIGUSR1, &sa, NULL) < 0)
! 	log_error(APLOG_LEVEL2, server_conf, "%s: sigaction(SIGUSR1)", strerror(errno));
  #else
      if(!one_process) {
  	signal (SIGSEGV, (void (*)(int))seg_fault);
***************
*** 1578,1584 ****
        uid_t uid=atoi(&user_name[1]);
  
        if ((ent = getpwuid(uid)) == NULL) {
! 	 log_unixerr("getpwuid",NULL,"couldn't determine user name from uid", server_conf);
  	 exit(1);
        }
        
--- 1585,1593 ----
        uid_t uid=atoi(&user_name[1]);
  
        if ((ent = getpwuid(uid)) == NULL) {
! 	 log_error(APLOG_LEVEL2, server_conf,
! 		   "%s: getpwuid: couldn't determine user name from uid",
! 		   strerror(errno));
  	 exit(1);
        }
        
***************
*** 1591,1607 ****
      /* Reset `groups' attributes. */
      
      if (initgroups(name, group_id) == -1) {
! 	log_unixerr("initgroups", NULL, "unable to set groups", server_conf);
  	exit (1);
      }
  #ifdef MULTIPLE_GROUPS
      if (getgroups(NGROUPS_MAX, group_id_list) == -1) {
! 	log_unixerr("getgroups", NULL, "unable to get group list", server_conf);
  	exit (1);
      }
  #endif
      if (setgid(group_id) == -1) {
! 	log_unixerr("setgid", NULL, "unable to set group id", server_conf);
  	exit (1);
      }
  #endif 
--- 1600,1619 ----
      /* Reset `groups' attributes. */
      
      if (initgroups(name, group_id) == -1) {
! 	log_error(APLOG_LEVEL2, server_conf,
! 		  "%s: initgroups: unable to set groups", strerror(errno));
  	exit (1);
      }
  #ifdef MULTIPLE_GROUPS
      if (getgroups(NGROUPS_MAX, group_id_list) == -1) {
! 	log_error(APLOG_LEVEL2, server_conf,
! 		  "%s: getgroups: unable to get group list", strerror(errno));
  	exit (1);
      }
  #endif
      if (setgid(group_id) == -1) {
! 	log_error(APLOG_LEVEL2, server_conf,
! 		  "%s: setgid: unable to set group id", strerror(errno));
  	exit (1);
      }
  #endif 
***************
*** 1801,1807 ****
  
      if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char*)&just_say_no,
                     sizeof(int)) < 0) {
!         log_unixerr("setsockopt", "(TCP_NODELAY)", NULL, server_conf);
      }
  }
  #else
--- 1813,1820 ----
  
      if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char*)&just_say_no,
                     sizeof(int)) < 0) {
!         log_error(APLOG_LEVEL3, server_conf, "%s: setsockopt (TCP_NODELAY)",
! 		  strerror(errno));
      }
  }
  #else
***************
*** 1814,1821 ****
      int one = 1;
  
      if ((s = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)) == -1) {
!         log_unixerr("socket", NULL, "Failed to get a socket, exiting child",
!                     server_conf);
          exit(1);
      }
  
--- 1827,1835 ----
      int one = 1;
  
      if ((s = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)) == -1) {
!         log_error(APLOG_LEVEL2, server_conf,
! 		  "%s: socket: Failed to get a socket, exiting child",
! 		  strerror(errno));
          exit(1);
      }
  
***************
*** 1824,1835 ****
  #ifndef MPE
  /* MPE does not support SO_REUSEADDR and SO_KEEPALIVE */
      if (setsockopt(s, SOL_SOCKET,SO_REUSEADDR,(char *)&one,sizeof(int)) < 0) {
!         log_unixerr("setsockopt", "(SO_REUSEADDR)", NULL, server_conf);
          exit(1);
      }
      one = 1;
      if (setsockopt(s, SOL_SOCKET,SO_KEEPALIVE,(char *)&one,sizeof(int)) < 0) {
!         log_unixerr("setsockopt", "(SO_KEEPALIVE)", NULL, server_conf);
          exit(1);
      }
  #endif
--- 1838,1851 ----
  #ifndef MPE
  /* MPE does not support SO_REUSEADDR and SO_KEEPALIVE */
      if (setsockopt(s, SOL_SOCKET,SO_REUSEADDR,(char *)&one,sizeof(int)) < 0) {
!         log_error(APLOG_LEVEL1, server_conf, "%s: setsockopt (SO_REUSEADDR)",
! 		  strerror(errno));
          exit(1);
      }
      one = 1;
      if (setsockopt(s, SOL_SOCKET,SO_KEEPALIVE,(char *)&one,sizeof(int)) < 0) {
!         log_error(APLOG_LEVEL1, server_conf, "%s: setsockopt (SO_KEEPALIVE)",
! 		  strerror(errno));
          exit(1);
      }
  #endif
***************
*** 1859,1867 ****
      if (server_conf->send_buffer_size) {
          if (setsockopt(s, SOL_SOCKET, SO_SNDBUF,
                (char *)&server_conf->send_buffer_size, sizeof(int)) < 0) {
!             log_unixerr("setsockopt", "(SO_SNDBUF)",
!                         "Failed to set SendBufferSize, using default",
!                         server_conf);
  	    /* not a fatal error */
  	}
      }
--- 1875,1883 ----
      if (server_conf->send_buffer_size) {
          if (setsockopt(s, SOL_SOCKET, SO_SNDBUF,
                (char *)&server_conf->send_buffer_size, sizeof(int)) < 0) {
!             log_error(APLOG_LEVEL2, server_conf,
! 		      "%s: setsockopt: (SO_SNDBUF) Failed to set SendBufferSize, using default",
! 		      strerror(errno));
  	    /* not a fatal error */
  	}
      }
***************
*** 2039,2045 ****
      /* Only try to switch if we're running as root */
      if (!geteuid() && setuid(user_id) == -1) {
  #endif
!         log_unixerr("setuid", NULL, "unable to change uid", server_conf);
  	exit (1);
      }
  #ifdef MPE
--- 2055,2062 ----
      /* Only try to switch if we're running as root */
      if (!geteuid() && setuid(user_id) == -1) {
  #endif
!         log_error(APLOG_LEVEL2, server_conf,
! 		  "%s: setuid: unable to change uid", strerror(errno));
  	exit (1);
      }
  #ifdef MPE
***************
*** 2112,2118 ****
  
              errno = errsave;
              if (srv < 0 && errno != EINTR)
!                 log_unixerr("select", "(listen)", NULL, server_conf);
  
              if (srv <= 0)
                  continue;
--- 2129,2136 ----
  
              errno = errsave;
              if (srv < 0 && errno != EINTR)
!                 log_error(APLOG_LEVEL2, server_conf,
! 			  "%s: select: (listen)", strerror(errno));
  
              if (srv <= 0)
                  continue;
***************
*** 2149,2155 ****
  #elif defined(ECONNABORTED)
                if (errno != ECONNABORTED)
  #endif
!                 log_unixerr("accept", "(client socket)", NULL, server_conf);
              }
  
  	    /* go around again, safe to die */
--- 2167,2174 ----
  #elif defined(ECONNABORTED)
                if (errno != ECONNABORTED)
  #endif
!                 log_error(APLOG_LEVEL2, server_conf, "%s: accept: (client socket)",
! 			  strerror(errno));
              }
  
  	    /* go around again, safe to die */
***************
*** 2176,2182 ****
  
  	clen = sizeof(sa_server);
  	if (getsockname(csd, &sa_server, &clen) < 0) {
! 	    log_unixerr("getsockname", NULL, NULL, server_conf);
  	    continue;
  	}
  
--- 2195,2202 ----
  
  	clen = sizeof(sa_server);
  	if (getsockname(csd, &sa_server, &clen) < 0) {
! 	    log_error(APLOG_LEVEL1, server_conf, "%s: getsockname:",
! 		      strerror(errno));
  	    continue;
  	}
  
***************
*** 2189,2195 ****
  	dupped_csd = csd;
  #if defined(NEED_DUPPED_CSD)
  	if ((dupped_csd = dup(csd)) < 0) {
! 	    log_unixerr("dup", NULL, "couldn't duplicate csd", server_conf);
  	    dupped_csd = csd;   /* Oh well... */
  	}
  	note_cleanups_for_fd(ptrans,dupped_csd);
--- 2209,2216 ----
  	dupped_csd = csd;
  #if defined(NEED_DUPPED_CSD)
  	if ((dupped_csd = dup(csd)) < 0) {
! 	    log_error(APLOG_LEVEL2, server_conf,
! 		      "%s: dup: couldn't duplicate csd", strerror(errno));
  	    dupped_csd = csd;   /* Oh well... */
  	}
  	note_cleanups_for_fd(ptrans,dupped_csd);
***************
*** 2286,2292 ****
      (void)update_child_status (child_num, SERVER_STARTING, (request_rec *)NULL);
  
      if ((pid = fork()) == -1) {
! 	log_unixerr("fork", NULL, "Unable to fork new process", server_conf);
  
  	/* fork didn't succeed. Fix the scoreboard or else
  	 * it will say SERVER_STARTING forever and ever
--- 2307,2314 ----
      (void)update_child_status (child_num, SERVER_STARTING, (request_rec *)NULL);
  
      if ((pid = fork()) == -1) {
! 	log_error(APLOG_LEVEL1, server_conf,
! 		  "%s: fork: Unable to fork new process", strerror(errno));
  
  	/* fork didn't succeed. Fix the scoreboard or else
  	 * it will say SERVER_STARTING forever and ever
***************
*** 2412,2419 ****
  	    }
  	}
  
! 	log_error ("Server configured -- resuming normal operations",
! 	    server_conf);
  	restart_pending = 0;
  
  	while (!restart_pending) {
--- 2434,2442 ----
  	    }
  	}
  
! 	log_error(APLOG_LEVEL3, server_conf, "%s",
! 		  "Server configured -- resuming normal operations");
! 	
  	restart_pending = 0;
  
  	while (!restart_pending) {
***************
*** 2493,2502 ****
  	    scoreboard_image->global.exit_generation = generation;
  	    update_scoreboard_global ();
  
! 	    log_error ("SIGUSR1 received.  Doing graceful restart",server_conf);
  	    /* kill off the idle ones */
  	    if (ap_killpg(pgrp, SIGUSR1) < 0) {
! 		log_unixerr ("killpg SIGUSR1", NULL, NULL, server_conf);
  	    }
  #ifndef SCOREBOARD_FILE
  	    /* This is mostly for debugging... so that we know what is still
--- 2516,2528 ----
  	    scoreboard_image->global.exit_generation = generation;
  	    update_scoreboard_global ();
  
! 	    log_error(APLOG_LEVEL3, server_conf, "%s",
! 		      "SIGUSR1 received.  Doing graceful restart");
! 
  	    /* kill off the idle ones */
  	    if (ap_killpg(pgrp, SIGUSR1) < 0) {
! 		log_error(APLOG_LEVEL2, server_conf,
! 			  "%s: killpg SIGUSR1:", strerror(errno));
  	    }
  #ifndef SCOREBOARD_FILE
  	    /* This is mostly for debugging... so that we know what is still
***************
*** 2515,2524 ****
  	else {
  	    /* Kill 'em off */
  	    if (ap_killpg (pgrp, SIGHUP) < 0) {
! 		log_unixerr ("killpg SIGHUP", NULL, NULL, server_conf);
  	    }
  	    reclaim_child_processes(); /* Not when just starting up */
! 	    log_error ("SIGHUP received.  Attempting to restart", server_conf);
  	}
  	++generation;
  
--- 2541,2552 ----
  	else {
  	    /* Kill 'em off */
  	    if (ap_killpg (pgrp, SIGHUP) < 0) {
! 		log_error(APLOG_LEVEL2, server_conf,
! 			  "%s: killpg SIGHUP:", strerror(errno));
  	    }
  	    reclaim_child_processes(); /* Not when just starting up */
! 	    log_error(APLOG_LEVEL3, server_conf, "%s",
! 		      "SIGHUP received.  Attempting to restart");
  	}
  	++generation;
  
***************
*** 2619,2625 ****
        /* Only try to switch if we're running as root */
        if(!geteuid() && setuid(user_id) == -1) {
  #endif
!           log_unixerr("setuid", NULL, "unable to change uid", server_conf);
            exit (1);
        }
  #ifdef MPE
--- 2647,2654 ----
        /* Only try to switch if we're running as root */
        if(!geteuid() && setuid(user_id) == -1) {
  #endif
!           log_error(APLOG_LEVEL1, server_conf,
! 		    "%s: setuid: unable to change uid", strerror(errno));
            exit (1);
        }
  #ifdef MPE
***************
*** 2858,2864 ****
  
  	clen = sizeof(sa_server);
  	if (getsockname(csd, &sa_server, &clen) < 0) {
! 	    log_unixerr("getsockname", NULL, NULL, server_conf);
  	    continue;
  	}
          clen = sizeof(sa_client);
--- 2887,2894 ----
  
  	clen = sizeof(sa_server);
  	if (getsockname(csd, &sa_server, &clen) < 0) {
! 	    log_error(APLOG_LEVEL2, server_conf,
! 		      "%s: getsockname:", strerror(errno));
  	    continue;
  	}
          clen = sizeof(sa_client);
***************
*** 2878,2884 ****
  	dupped_csd = csd;
  #if defined(NEED_DUPPED_CSD)
  	if ((dupped_csd = dup(csd)) < 0) {
! 	    log_unixerr("dup", NULL, "couldn't duplicate csd", server_conf);
  	    dupped_csd = csd;   /* Oh well... */
  	}
  	note_cleanups_for_socket(pchild,dupped_csd);
--- 2908,2915 ----
  	dupped_csd = csd;
  #if defined(NEED_DUPPED_CSD)
  	if ((dupped_csd = dup(csd)) < 0) {
! 	    log_error(APLOG_LEVEL2, server_conf,
! 		      "%s: dup: couldn't duplicate csd", strerror(errno));
  	    dupped_csd = csd;   /* Oh well... */
  	}
  	note_cleanups_for_socket(pchild,dupped_csd);
***************
*** 3142,3148 ****
  #endif /* WIN32 */
  
          if (srv < 0 && errno != EINTR)
!             log_unixerr("select", "(listen)", NULL, server_conf);
  
          if (srv < 0)
              continue;
--- 3173,3180 ----
  #endif /* WIN32 */
  
          if (srv < 0 && errno != EINTR)
!             log_error(APLOG_LEVEL2, server_conf,
! 		      "%s: select: (listen)", strerror(errno));
  
          if (srv < 0)
              continue;
***************
*** 3191,3197 ****
  #elif defined(ECONNABORTED)
                      if (errno != ECONNABORTED)
  #endif
!                         log_unixerr("accept", "(client socket)", NULL, server_conf);
          }
          else
          {
--- 3223,3230 ----
  #elif defined(ECONNABORTED)
                      if (errno != ECONNABORTED)
  #endif
!                         log_error(APLOG_LEVEL2, server_conf,
! 				  "%s: accept: (client socket)", strerror(errno));
          }
          else
          {
Index: httpd.h
===================================================================
RCS file: /export/home/cvs/apache/src/httpd.h,v
retrieving revision 1.113
diff -c -c -r1.113 httpd.h
*** httpd.h	1997/06/15 19:22:28	1.113
--- httpd.h	1997/06/22 03:20:36
***************
*** 603,608 ****
--- 603,609 ----
    
      char *error_fname;
      FILE *error_log;
+     int loglevel;
    
      /* Module-specific configuration for server, and defaults... */
  



Re: [PATCH] Loglevels and logging routine consolidation

Posted by Dean Gaudet <dg...@arctic.org>.
This is cool.  Here's some suggestions:

Give the levels names... such as debug, info, warn, error

Get rid of all perror() and stderr output calls.  Make them use log_error.
Make log_error print on stderr until the error_log is opened.  When the
error_log is opened (or at detach time) connect stderr to the error_log.

As soon as the server starts, reopen stdin and stdout from /dev/null.

After you do that we'll have a server which prints fatal errors on
stderr when run at the command line.  And which closes all of 0,1,2 so
that there's no fear of it writing crud in the background on your tty.
It will also error_log all non-fatal config warnings (since it parses
the config twice).

Then you can start the server with something like this:

env - [misc env settings the server really needs] \
    httpd -d /wherever 2>&1 | logger -p daemon.alert -t httpd

And it'll log those initial errors (should there be any) to syslog.

I've got a suspended PR that suggests this too.

Dean