httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Randy Terbush <ra...@hyperreal.org>
Subject cvs commit: apachen/src/main http_core.c http_core.h http_log.c http_log.h
Date Mon, 25 Aug 1997 02:00:45 GMT
randy       97/08/24 19:00:43

  Modified:    src      CHANGES
               src/main http_core.c http_core.h http_log.c http_log.h
  Log:
  Add LogLevels functionality through the addition of aplog_error().
  This change also provides the ability to log errors via syslogd.
  Reviewed by:	Dean Gaudet, Jim Jagielski, Ken Coar
  
  Revision  Changes    Path
  1.418     +6 -0      apachen/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/CHANGES,v
  retrieving revision 1.417
  retrieving revision 1.418
  diff -u -r1.417 -r1.418
  --- CHANGES	1997/08/24 18:46:16	1.417
  +++ CHANGES	1997/08/25 02:00:27	1.418
  @@ -1,5 +1,11 @@
   Changes with Apache 1.3a2
   
  +  *) Add aplog_error() providing a mechanism to define levels of
  +     verbosity to the server error logging. This addition also provides
  +     the ablity to log errors using syslogd. Error logging is configurable
  +     on a per-directory basis using the LogLevel directive. Conversion
  +     of log_*() in progress. [Randy Terbush]
  +
     *) Canonicalise filenames under Win32. Short filenames are
        converted to long ones. Backslashes are converted to forward
   	 slashes. Case is converted to lower. Parts of URLs that do not
  
  
  
  1.114     +31 -0     apachen/src/main/http_core.c
  
  Index: http_core.c
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/main/http_core.c,v
  retrieving revision 1.113
  retrieving revision 1.114
  diff -u -r1.113 -r1.114
  --- http_core.c	1997/08/23 01:52:51	1.113
  +++ http_core.c	1997/08/25 02:00:38	1.114
  @@ -130,6 +130,8 @@
       conf->limit_nproc = NULL;
   #endif
   
  +    conf->loglevel = DEFAULT_LOGLEVEL;
  +    
       conf->sec = make_array (a, 2, sizeof(void *));
   
       return (void *)conf;
  @@ -1372,6 +1374,34 @@
       return NULL;
   }
   
  +const char *set_loglevel (cmd_parms *cmd, core_dir_config *conf, const char *arg) 
  +{
  +   char *str;
  +    
  +   if ((str = getword_conf(cmd->pool, &arg))) {
  +       if (!strcasecmp(str, "emerg"))
  +	   conf->loglevel = APLOG_EMERG;
  +       else if (!strcasecmp(str, "alert"))
  +	   conf->loglevel = APLOG_ALERT;
  +       else if (!strcasecmp(str, "crit"))
  +	   conf->loglevel = APLOG_CRIT;
  +       else if (!strcasecmp(str, "error"))
  +	   conf->loglevel = APLOG_ERR;
  +       else if (!strcasecmp(str, "warn"))
  +	   conf->loglevel = APLOG_WARNING;
  +       else if (!strcasecmp(str, "notice"))
  +	   conf->loglevel = APLOG_NOTICE;
  +       else if (!strcasecmp(str, "info"))
  +	   conf->loglevel = APLOG_INFO;
  +       else if (!strcasecmp(str, "debug"))
  +	   conf->loglevel = APLOG_DEBUG;
  +   }
  +   else
  +       return "LogLevel requires level keyword";
  +   
  +   return NULL;
  +}
  +
   /* Note --- ErrorDocument will now work from .htaccess files.  
    * The AllowOverride of Fileinfo allows webmasters to turn it off
    */
  @@ -1498,6 +1528,7 @@
   { "ListenBacklog", set_listenbacklog, NULL, RSRC_CONF, TAKE1, "maximum length of the queue
of pending connections, as used by listen(2)" },
   { "CoreDumpDirectory", set_coredumpdir, NULL, RSRC_CONF, TAKE1, "The location of the directory
Apache changes to before dumping core" },
   { "Include", include_config, NULL, RSRC_CONF, TAKE1, "config file to be included" },
  +{ "LogLevel", set_loglevel, (void*)XtOffsetOf(core_dir_config, loglevel), OR_ALL, TAKE1,
"set level of verbosity in error logging" },
   { NULL },
   };
   
  
  
  
  1.28      +3 -0      apachen/src/main/http_core.h
  
  Index: http_core.h
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/main/http_core.h,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- http_core.h	1997/08/23 16:17:12	1.27
  +++ http_core.h	1997/08/25 02:00:39	1.28
  @@ -189,6 +189,9 @@
       struct rlimit *limit_nproc;
   #endif
   
  +    /* logging options */
  +    int loglevel;
  +    
       /* Access control */
       array_header *sec;
       regex_t *r;
  
  
  
  1.22      +144 -33   apachen/src/main/http_log.c
  
  Index: http_log.c
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/main/http_log.c,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- http_log.c	1997/07/21 05:53:43	1.21
  +++ http_log.c	1997/08/25 02:00:40	1.22
  @@ -58,15 +58,52 @@
    */
   
   
  +#define CORE_PRIVATE
   #include "httpd.h"
   #include "http_config.h"
   #include "http_core.h"
   #include "http_log.h"
   
   #include <stdarg.h>
  +#include <syslog.h>
   
  -static int
  -error_log_child (void *cmd)
  +static TRANS facilities[] = {
  +    {"auth",	LOG_AUTH},
  +    {"authpriv",LOG_AUTHPRIV},
  +    {"cron", 	LOG_CRON},
  +    {"daemon",	LOG_DAEMON},
  +    {"ftp",	LOG_FTP},
  +    {"kern",	LOG_KERN},
  +    {"lpr",	LOG_LPR},
  +    {"mail",	LOG_MAIL},
  +    {"news",	LOG_NEWS},
  +    {"syslog",	LOG_SYSLOG},
  +    {"user",	LOG_USER},
  +    {"uucp",	LOG_UUCP},
  +    {"local0",	LOG_LOCAL0},
  +    {"local1",	LOG_LOCAL1},
  +    {"local2",	LOG_LOCAL2},
  +    {"local3",	LOG_LOCAL3},
  +    {"local4",	LOG_LOCAL4},
  +    {"local5",	LOG_LOCAL5},
  +    {"local6",	LOG_LOCAL6},
  +    {"local7",	LOG_LOCAL7},
  +    {NULL,		-1},
  +};
  +
  +static TRANS priorities[] = {
  +    {"emerg",	APLOG_EMERG},
  +    {"alert",	APLOG_ALERT},
  +    {"crit",	APLOG_CRIT},
  +    {"error",	APLOG_ERR},
  +    {"warn",	APLOG_WARNING},
  +    {"notice",	APLOG_NOTICE},
  +    {"info",	APLOG_INFO},
  +    {"debug",	APLOG_DEBUG},
  +    {NULL,	-1},
  +};
  +
  +static int error_log_child (void *cmd)
   {
       /* Child process code for 'ErrorLog "|..."';
        * may want a common framework for this, since I expect it will
  @@ -92,29 +129,47 @@
       return(child_pid);
   }
   
  -void open_error_log(server_rec *s, pool *p)
  +void open_error_log (server_rec *s, pool *p)
   {
       char *fname;
  -  
  -    fname = server_root_relative (p, s->error_fname);
  +    register TRANS *fac;
  +
   
       if (*s->error_fname == '|') {
  -      FILE *dummy;
  +	FILE *dummy;
  +
  +	if (!spawn_child (p, error_log_child, (void *)(s->error_fname+1),
  +			  kill_after_timeout, &dummy, NULL)) {
  +	    perror ("spawn_child");
  +	    fprintf (stderr, "Couldn't fork child for ErrorLog process\n");
  +	    exit (1);
  +	}
   
  -      if (!spawn_child (p, error_log_child, (void *)(s->error_fname+1),
  -                    kill_after_timeout, &dummy, NULL)) {
  -	perror ("spawn_child");
  -	fprintf (stderr, "Couldn't fork child for ErrorLog process\n");
  -	exit (1);
  -      }
  +	s->error_log = dummy;
  +    }
  +    else if (!strncasecmp(s->error_fname, "syslog", 6)) {
  +	if ((fname = strchr(s->error_fname, ':'))) {
  +	    fname++;
  +	    for (fac = facilities; fac->t_name; fac++) {
  +		if (!strcasecmp(fname, fac->t_name)) {
  +		    openlog("httpd", LOG_NDELAY|LOG_CONS|LOG_PID, fac->t_val);
  +		    s->error_log = NULL;
  +		    return;
  +		}
  +	    }
  +	}
  +	else
  +	    openlog("httpd", LOG_NDELAY|LOG_CONS|LOG_PID, LOG_LOCAL7);
   
  -      s->error_log = dummy;
  -    } else {
  +	s->error_log = NULL;
  +    }
  +    else {
  +	fname = server_root_relative (p, s->error_fname);
           if(!(s->error_log = pfopen(p, fname, "a"))) {
               perror("fopen");
               fprintf(stderr,"httpd: could not open error log file %s.\n", fname);
               exit(1);
  -      }
  +	}
       }
   }
   
  @@ -139,12 +194,67 @@
       }
   }
   
  -API_EXPORT(void) error_log2stderr(server_rec *s) {
  +API_EXPORT(void) error_log2stderr (server_rec *s) {
       if(fileno(s->error_log) != STDERR_FILENO)
           dup2(fileno(s->error_log),STDERR_FILENO);
   }
   
  -void log_pid(pool *p, char *pid_fname) {
  +API_EXPORT(void) aplog_error (const char *file, int line, int level,
  +			      const request_rec *r, const char *fmt, ...)
  +{
  +    core_dir_config *conf;
  +    va_list args;
  +    char errstr[MAX_STRING_LEN];
  +    static TRANS *pname = priorities;
  +    
  +
  +    if (r != NULL) { /* backward compatibilty for historic logging functions */
  +	conf = get_module_config(r->per_dir_config, &core_module);
  +
  +	if (level > conf->loglevel)
  +	    return;
  +
  +	switch (conf->loglevel) {
  +	case APLOG_DEBUG:
  +	    ap_snprintf(errstr, sizeof(errstr), "[%s] %d: %s: %s: %d: ",
  +			pname[level].t_name, errno, strerror(errno), file, line);
  +	    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));
  +	    break;
  +	case APLOG_INFO:
  +	case APLOG_ERR:
  +	case APLOG_WARNING:
  +	case APLOG_NOTICE:
  +	    ap_snprintf(errstr, sizeof(errstr), "[%s]", pname[level].t_name);
  +	    break;
  +	}
  +    }
  +    else
  +	ap_snprintf(errstr, sizeof(errstr), "[%s]", pname[level].t_name);
  +	
  +    va_start(args, fmt);
  +
  +    /* NULL if we are logging to syslog */
  +    if (r->server->error_log) {
  +	fprintf(r->server->error_log, "[%s] %s", get_time(), errstr);
  +	vfprintf(r->server->error_log, fmt, args);
  +	fflush(r->server->error_log);
  +    }
  +    else {
  +	if (errstr)
  +	    syslog(level, "%s", errstr);
  +
  +	vsyslog(level, fmt, args);
  +    }
  +    
  +    va_end(args);
  +}
  +
  +void log_pid (pool *p, char *pid_fname) {
       FILE *pid_file;
   
       if (!pid_fname) return;
  @@ -158,13 +268,14 @@
       fclose(pid_file);
   }
   
  -API_EXPORT(void) log_error(const char *err, server_rec *s) {
  +API_EXPORT(void) log_error (const char *err, server_rec *s)
  +{
       fprintf(s->error_log, "[%s] %s\n",get_time(),err);
       fflush(s->error_log);
   }
   
  -API_EXPORT(void) log_unixerr(const char *routine, const char *file,
  -			     const char *msg, server_rec *s)
  +API_EXPORT(void) log_unixerr (const char *routine, const char *file,
  +			      const char *msg, server_rec *s)
   {
       const char *p, *q;
       FILE *err=s ? s->error_log : stderr;
  @@ -181,33 +292,33 @@
       fflush(err);
   }
   
  -API_EXPORT(void) log_printf(const server_rec *s, const char *fmt, ...)
  +API_EXPORT(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);
  -    va_end (args);
  +    va_start(args, fmt);
  +    vfprintf(s->error_log, fmt, args);
  +    va_end(args);
   
       fputc('\n', s->error_log);
       fflush(s->error_log);
   }
   
  -API_EXPORT(void) log_reason(const char *reason, const char *file, request_rec *r) 
  +API_EXPORT(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,
  -	     get_remote_host(r->connection, r->per_dir_config, REMOTE_NAME),
  -	     reason);
  -    fflush (r->server->error_log);
  +    fprintf(r->server->error_log,
  +	    "[%s] access to %s failed for %s, reason: %s\n",
  +	    get_time(), file,
  +	    get_remote_host(r->connection, r->per_dir_config, REMOTE_NAME),
  +	    reason);
  +    fflush(r->server->error_log);
   }
   
  -API_EXPORT(void) log_assert(const char *szExp, const char *szFile, int nLine)
  +API_EXPORT(void) log_assert (const char *szExp, const char *szFile, int nLine)
   {
       fprintf(stderr, "[%s] file %s, line %d, assertion \"%s\" failed\n",
  -	get_time(), szFile, nLine, szExp);
  +	    get_time(), szFile, nLine, szExp);
   #ifndef WIN32
       /* unix assert does an abort leading to a core dump */
       abort();
  
  
  
  1.11      +18 -0     apachen/src/main/http_log.h
  
  Index: http_log.h
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/main/http_log.h,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- http_log.h	1997/07/21 05:53:43	1.10
  +++ http_log.h	1997/08/25 02:00:40	1.11
  @@ -50,7 +50,25 @@
    *
    */
   
  +#define	APLOG_EMERG	0	/* system is unusable */
  +#define	APLOG_ALERT	1	/* action must be taken immediately */
  +#define	APLOG_CRIT	2	/* critical conditions */
  +#define	APLOG_ERR	3	/* error conditions */
  +#define	APLOG_WARNING	4	/* warning conditions */
  +#define	APLOG_NOTICE	5	/* normal but significant condition */
  +#define	APLOG_INFO	6	/* informational */
  +#define	APLOG_DEBUG	7	/* debug-level messages */
  +#define DEFAULT_LOGLEVEL	APLOG_ERR
  +#define APLOG_MARK	__FILE__,__LINE__
  +
  +typedef struct _trans {
  +	char	*t_name;
  +	int	t_val;
  +} TRANS;
  +
   void open_logs (server_rec *, pool *p);
  +API_EXPORT(void) aplog_error(const char *file, int line, int level,
  +			     const request_rec *r, const char *fmt, ...);
   API_EXPORT(void) error_log2stderr (server_rec *);     
   
   void log_pid (pool *p, char *fname);
  
  
  

Mime
View raw message