randy 97/08/26 22:45:41
Modified: src CHANGES
src/main http_config.c http_core.c http_log.c http_log.h
httpd.h
Log:
Backoff aplog_error() to be configureable on a per-server basis.
Attempt to fix portability issues with syslog().
Convert existing log functions to wrappers for aplog_error().
Add #ifdef USE_SYSLOG
Revision Changes Path
1.423 +1 -1 apachen/src/CHANGES
Index: CHANGES
===================================================================
RCS file: /export/home/cvs/apachen/src/CHANGES,v
retrieving revision 1.422
retrieving revision 1.423
diff -u -r1.422 -r1.423
--- CHANGES 1997/08/27 01:12:18 1.422
+++ CHANGES 1997/08/27 05:45:14 1.423
@@ -22,7 +22,7 @@
*) 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
+ on a per-server basis using the LogLevel directive. Conversion
of log_*() in progress. [Randy Terbush]
*) Canonicalise filenames under Win32. Short filenames are
1.77 +3 -0 apachen/src/main/http_config.c
Index: http_config.c
===================================================================
RCS file: /export/home/cvs/apachen/src/main/http_config.c,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -r1.76 -r1.77
--- http_config.c 1997/08/26 00:00:54 1.76
+++ http_config.c 1997/08/27 05:45:34 1.77
@@ -1081,6 +1081,8 @@
s->keep_alive = -1;
s->keep_alive_max = -1;
s->error_log = main_server->error_log;
+ s->loglevel = main_server->loglevel;
+
/* start the list of addreses */
addrs = &s->addrs;
while( hostname[0] ) {
@@ -1201,6 +1203,7 @@
s->server_hostname = NULL;
s->error_fname = DEFAULT_ERRORLOG;
s->error_log = stderr;
+ s->loglevel = DEFAULT_LOGLEVEL;
s->srm_confname = RESOURCE_CONFIG_FILE;
s->access_confname = ACCESS_CONFIG_FILE;
s->timeout = DEFAULT_TIMEOUT;
1.115 +10 -12 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.114
retrieving revision 1.115
diff -u -r1.114 -r1.115
--- http_core.c 1997/08/25 02:00:38 1.114
+++ http_core.c 1997/08/27 05:45:35 1.115
@@ -130,8 +130,6 @@
conf->limit_nproc = NULL;
#endif
- conf->loglevel = DEFAULT_LOGLEVEL;
-
conf->sec = make_array (a, 2, sizeof(void *));
return (void *)conf;
@@ -1374,27 +1372,27 @@
return NULL;
}
-const char *set_loglevel (cmd_parms *cmd, core_dir_config *conf, const char
*arg)
+const char *set_loglevel (cmd_parms *cmd, void *dummy, const char *arg)
{
char *str;
if ((str = getword_conf(cmd->pool, &arg))) {
if (!strcasecmp(str, "emerg"))
- conf->loglevel = APLOG_EMERG;
+ cmd->server->loglevel = APLOG_EMERG;
else if (!strcasecmp(str, "alert"))
- conf->loglevel = APLOG_ALERT;
+ cmd->server->loglevel = APLOG_ALERT;
else if (!strcasecmp(str, "crit"))
- conf->loglevel = APLOG_CRIT;
+ cmd->server->loglevel = APLOG_CRIT;
else if (!strcasecmp(str, "error"))
- conf->loglevel = APLOG_ERR;
+ cmd->server->loglevel = APLOG_ERR;
else if (!strcasecmp(str, "warn"))
- conf->loglevel = APLOG_WARNING;
+ cmd->server->loglevel = APLOG_WARNING;
else if (!strcasecmp(str, "notice"))
- conf->loglevel = APLOG_NOTICE;
+ cmd->server->loglevel = APLOG_NOTICE;
else if (!strcasecmp(str, "info"))
- conf->loglevel = APLOG_INFO;
+ cmd->server->loglevel = APLOG_INFO;
else if (!strcasecmp(str, "debug"))
- conf->loglevel = APLOG_DEBUG;
+ cmd->server->loglevel = APLOG_DEBUG;
}
else
return "LogLevel requires level keyword";
@@ -1528,7 +1526,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" },
+{ "LogLevel", set_loglevel, NULL, RSRC_CONF, TAKE1, "set level of verbosity
in error logging" },
{ NULL },
};
1.26 +44 -63 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.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- http_log.c 1997/08/25 14:53:39 1.25
+++ http_log.c 1997/08/27 05:45:36 1.26
@@ -65,6 +65,8 @@
#include "http_log.h"
#include <stdarg.h>
+
+#ifdef USE_SYSLOG
#include <syslog.h>
static TRANS facilities[] = {
@@ -94,6 +96,7 @@
{"local7", LOG_LOCAL7},
{NULL, -1},
};
+#endif
static TRANS priorities[] = {
{"emerg", APLOG_EMERG},
@@ -151,6 +154,7 @@
s->error_log = dummy;
}
+#ifdef USE_SYSLOG
else if (!strncasecmp(s->error_fname, "syslog", 6)) {
if ((fname = strchr(s->error_fname, ':'))) {
fname++;
@@ -167,6 +171,7 @@
s->error_log = NULL;
}
+#endif
else {
fname = server_root_relative (p, s->error_fname);
if(!(s->error_log = pfopen(p, fname, "a"))) {
@@ -204,63 +209,55 @@
}
API_EXPORT(void) aplog_error (const char *file, int line, int level,
- const request_rec *r, const char *fmt, ...)
+ const server_rec *s, 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 > s->loglevel)
+ return;
- 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;
- }
+ 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);
+ 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);
+ if (s->error_log) {
+ fprintf(s->error_log, "[%s] %s", get_time(), errstr);
+ vfprintf(s->error_log, fmt, args);
+ fflush(s->error_log);
}
-#ifdef NOTYET
+#ifdef USE_SYSLOG
else {
- if (errstr)
- syslog(level, "%s", errstr);
-
- vsyslog(level, fmt, args);
+ vsprintf(errstr + strlen(errstr), fmt, args);
+ syslog(level, "%s", errstr);
}
#endif
va_end(args);
}
-void log_pid (pool *p, char *pid_fname) {
+void log_pid (pool *p, char *pid_fname)
+{
FILE *pid_file;
if (!pid_fname) return;
@@ -276,49 +273,33 @@
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);
+ aplog_error(APLOG_MARK, APLOG_ERR, s, err);
}
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;
-
- p = strerror(errno);
- q = get_time();
-
- if (file != NULL)
- fprintf(err, "[%s] %s: %s: %s\n", q, routine, file, p);
- else
- fprintf(err, "[%s] %s: %s\n", q, routine, p);
- if (msg != NULL) fprintf(s->error_log, "[%s] - %s\n", q, msg);
-
- fflush(err);
+ aplog_error(file, 0, APLOG_ERR, s, msg);
}
API_EXPORT(void) log_printf (const server_rec *s, const char *fmt, ...)
{
+ char buf[MAX_STRING_LEN];
va_list args;
- fprintf(s->error_log, "[%s] ", get_time());
va_start(args, fmt);
- vfprintf(s->error_log, fmt, args);
+ vsprintf(buf, fmt, args);
+ aplog_error(APLOG_MARK, APLOG_ERR, s, buf);
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)
{
- 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);
+ aplog_error(APLOG_MARK, APLOG_ERR, r->server,
+ "access to %s failed for %s, reason: %s\n",
+ file,
+ get_remote_host(r->connection, r->per_dir_config, REMOTE_NAME),
+ reason);
}
API_EXPORT(void) log_assert (const char *szExp, const char *szFile, int
nLine)
1.12 +1 -1 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.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- http_log.h 1997/08/25 02:00:40 1.11
+++ http_log.h 1997/08/27 05:45:37 1.12
@@ -68,7 +68,7 @@
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, ...);
+ const server_rec *s, const char *fmt, ...);
API_EXPORT(void) error_log2stderr (server_rec *);
void log_pid (pool *p, char *fname);
1.146 +2 -1 apachen/src/main/httpd.h
Index: httpd.h
===================================================================
RCS file: /export/home/cvs/apachen/src/main/httpd.h,v
retrieving revision 1.145
retrieving revision 1.146
diff -u -r1.145 -r1.146
--- httpd.h 1997/08/25 17:10:18 1.145
+++ httpd.h 1997/08/27 05:45:37 1.146
@@ -723,7 +723,8 @@
char *error_fname;
FILE *error_log;
-
+ int loglevel;
+
/* Module-specific configuration for server, and defaults... */
int is_virtual; /* true if this is the virtual server */