You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Jon Travis <jt...@covalent.net> on 2001/10/09 00:32:30 UTC
error_log hook
The error log hook gets called with the post-formatted string in
addition to lots of mumbo-jumbo (like the date, remote client, etc.)
This patch gives authors the ability to use either the stripped down
log message, or the full one.
This section of code could also use some work (namely removing MAX_STRING_LEN
from everywhere, and replacing with a sizeof), but this keeps the patch small.
As an aside, one could have moved all this formatting functionality into a
simple core function which hooked into error_log, but as I recall the main
argument against this was because we wanted to make sure we always got
errors out to the file (REALLY_FIRST, anyone?)
Anyway, I would appreciate if someone could commit this patch.
-- Jon
Index: include/http_log.h
===================================================================
RCS file: /home/cvspublic/httpd-2.0/include/http_log.h,v
retrieving revision 1.31
diff -u -u -r1.31 http_log.h
--- include/http_log.h 2001/07/30 17:55:38 1.31
+++ include/http_log.h 2001/10/08 22:22:49
@@ -278,7 +278,7 @@
AP_DECLARE_HOOK(void, error_log, (const char *file, int line, int level,
apr_status_t status, const server_rec *s,
const request_rec *r, apr_pool_t *pool,
- const char *errstr))
+ const char *regerr, const char *errstr))
#ifdef __cplusplus
}
Index: server/log.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/server/log.c,v
retrieving revision 1.97
diff -u -u -r1.97 log.c
--- server/log.c 2001/09/18 22:13:57 1.97
+++ server/log.c 2001/10/08 22:22:50
@@ -338,8 +338,8 @@
const request_rec *r, apr_pool_t *pool,
const char *fmt, va_list args)
{
- char errstr[MAX_STRING_LEN];
- size_t len;
+ char errstr[MAX_STRING_LEN], regerr[MAX_STRING_LEN];
+ size_t len, reglen;
apr_file_t *logf = NULL;
const char *referer;
int level_and_mask = level & APLOG_LEVELMASK;
@@ -386,6 +386,7 @@
return;
}
+ reglen = apr_vsnprintf(regerr, sizeof(regerr), fmt, args);
if (logf && ((level & APLOG_STARTUP) != APLOG_STARTUP)) {
errstr[0] = '[';
apr_ctime(errstr + 1, apr_time_now());
@@ -439,8 +440,11 @@
len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
"(%d)%s: ", status, apr_strerror(status, buf, sizeof(buf)));
}
- len += apr_vsnprintf(errstr + len, MAX_STRING_LEN - len, fmt, args);
+ memcpy(errstr + len, regerr,
+ MAX_STRING_LEN - len < reglen ? MAX_STRING_LEN - len : reglen);
+ len += reglen;
+
if (r && (referer = apr_table_get(r->headers_in, "Referer"))) {
len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
", referer: %s", referer);
@@ -460,7 +464,7 @@
syslog(level_and_mask, "%s", errstr);
}
#endif
- ap_run_error_log(file, line, level, status, s, r, pool, errstr);
+ ap_run_error_log(file, line, level, status, s, r, pool, regerr, errstr);
}
AP_DECLARE(void) ap_log_error(const char *file, int line, int level,
@@ -760,6 +764,6 @@
(const char *file, int line, int level,
apr_status_t status, const server_rec *s,
const request_rec *r, apr_pool_t *pool,
- const char *errstr), (file, line, level,
- status, s, r, pool, errstr))
+ const char *regerr, const char *errstr),
+ (file, line, level, status, s, r, pool, regerr, errstr))
Re: error_log hook
Posted by Jon Travis <jt...@covalent.net>.
On Mon, Oct 08, 2001 at 04:16:44PM -0700, Ryan Bloom wrote:
> On Monday 08 October 2001 03:32 pm, Jon Travis wrote:
> > The error log hook gets called with the post-formatted string in
> > addition to lots of mumbo-jumbo (like the date, remote client, etc.)
> > This patch gives authors the ability to use either the stripped down
> > log message, or the full one.
> >
> > This section of code could also use some work (namely removing
> > MAX_STRING_LEN from everywhere, and replacing with a sizeof), but this
> > keeps the patch small.
> >
> > As an aside, one could have moved all this formatting functionality into a
> > simple core function which hooked into error_log, but as I recall the main
> > argument against this was because we wanted to make sure we always got
> > errors out to the file (REALLY_FIRST, anyone?)
> >
> > Anyway, I would appreciate if someone could commit this patch.
>
> This could be solved much more easily by just advancing the errstr string
> to be past the date/time portion. Commit coming within ten minutes.
Except you have that silly newline at the end of it. I don't
want your newline.. ;-)
-- Jon
Re: error_log hook
Posted by Ryan Bloom <rb...@covalent.net>.
On Monday 08 October 2001 03:32 pm, Jon Travis wrote:
> The error log hook gets called with the post-formatted string in
> addition to lots of mumbo-jumbo (like the date, remote client, etc.)
> This patch gives authors the ability to use either the stripped down
> log message, or the full one.
>
> This section of code could also use some work (namely removing
> MAX_STRING_LEN from everywhere, and replacing with a sizeof), but this
> keeps the patch small.
>
> As an aside, one could have moved all this formatting functionality into a
> simple core function which hooked into error_log, but as I recall the main
> argument against this was because we wanted to make sure we always got
> errors out to the file (REALLY_FIRST, anyone?)
>
> Anyway, I would appreciate if someone could commit this patch.
This could be solved much more easily by just advancing the errstr string
to be past the date/time portion. Commit coming within ten minutes.
Ryan
______________________________________________________________
Ryan Bloom rbb@apache.org
Covalent Technologies rbb@covalent.net
--------------------------------------------------------------