Hi,
I have factored two chunks out of the per-module LogLevel patch which
make sense and could be commited to trunk even without the rest of the
patch:
ap_log_error_wrapper.diff:
On C99 compilers, avoid argument setup and function call overhead if
the log message will be discarded anyway. Also allow to disable higher
loglevels at compile time by defining APLOG_MAX_LOGLEVEL.
On pre-C99 compilers, it should just work like before.
loglevel_trace.diff:
Introduce additional log levels trace1 ... trace8 above the debug
level.
Comments?
Cheers,
Stefan
diff --git a/configure.in b/configure.in
index dc487c1..b6cb11c 100644
--- a/configure.in
+++ b/configure.in
@@ -170,6 +170,9 @@ dnl PCRE and for our config tests will be whatever PCRE determines.
AC_PROG_CC
AC_PROG_CPP
+dnl Try to get c99 support for variadic macros
+AC_PROG_CC_C99
+
if test "x${cache_file}" = "x/dev/null"; then
# Likewise, ensure that CC and CPP are passed through to the pcre
# configure script iff caching is disabled (the autoconf 2.5x default).
diff --git a/include/ap_mmn.h b/include/ap_mmn.h
index 3eb0aeb..beb3374 100644
--- a/include/ap_mmn.h
+++ b/include/ap_mmn.h
@@ -213,6 +213,9 @@
* 20091230.1 (2.3.5-dev) add util_ldap_state_t.opTimeout
* 20091230.2 (2.3.5-dev) add ap_get_server_name_for_url()
* 20091230.3 (2.3.6-dev) add ap_parse_log_level()
+ * 20100202.0 (2.3.6-dev) Make ap_log_*error macro wrappers around
+ * ap_log_*error_ to save argument preparation and
+ * function call overhead.
*
*/
diff --git a/include/http_log.h b/include/http_log.h
index d8d2b02..ef475a2 100644
--- a/include/http_log.h
+++ b/include/http_log.h
@@ -91,6 +91,28 @@ extern "C" {
#define DEFAULT_LOGLEVEL APLOG_WARNING
#endif
+#ifndef APLOG_MAX_LOGLEVEL
+#define APLOG_IS_LEVEL(s,level) \
+ ((s == NULL) || \
+ ((s)->loglevel >= ((level)& APLOG_LEVELMASK)))
+#else
+#define APLOG_IS_LEVEL(s,level) \
+ (((level) <= APLOG_MAX_LOGLEVEL) && \
+ ((s == NULL) || \
+ ((s)->loglevel >= ((level) & APLOG_LEVELMASK))))
+#endif
+
+#define APLOGinfo(s) APLOG_IS_LEVEL(s,APLOG_INFO)
+#define APLOGdebug(s) APLOG_IS_LEVEL(s,APLOG_DEBUG)
+
+#define APLOG_R_IS_LEVEL(r,level) APLOG_IS_LEVEL(r->server,level)
+#define APLOGrinfo(r) APLOG_R_IS_LEVEL(r,APLOG_INFO)
+#define APLOGrdebug(r) APLOG_R_IS_LEVEL(r,APLOG_DEBUG)
+
+#define APLOG_C_IS_LEVEL(c,level) APLOG_IS_LEVEL(c->base_server,level)
+#define APLOGcinfo(c) APLOG_C_IS_LEVEL(c,APLOG_INFO)
+#define APLOGcdebug(c) APLOG_C_IS_LEVEL(c,APLOG_DEBUG)
+
extern int AP_DECLARE_DATA ap_default_loglevel;
#define APLOG_MARK __FILE__,__LINE__
@@ -164,10 +186,20 @@ void ap_logs_child_init(apr_pool_t *p, server_rec *s);
* simple format string like "%s", followed by the string containing the
* untrusted data.
*/
-AP_DECLARE(void) ap_log_error(const char *file, int line, int level,
- apr_status_t status, const server_rec *s,
- const char *fmt, ...)
- __attribute__((format(printf,6,7)));
+#if __STDC_VERSION__ >= 199901L
+/* need additional step to expand APLOG_MARK first */
+#define ap_log_error(...) ap_log_error__(__VA_ARGS__)
+#define ap_log_error__(file, line, level, status, s, ...) \
+ do { server_rec *sr = s; if (APLOG_IS_LEVEL(sr, level)) \
+ ap_log_error_(file, line, level, status, sr, __VA_ARGS__); \
+ } while(0)
+#else
+#define ap_log_error ap_log_error_
+#endif
+AP_DECLARE(void) ap_log_error_(const char *file, int line, int level,
+ apr_status_t status, const server_rec *s,
+ const char *fmt, ...)
+ __attribute__((format(printf,6,7)));
/**
* ap_log_perror() - log messages which are not related to a particular
@@ -212,9 +244,19 @@ AP_DECLARE(void) ap_log_perror(const char *file, int line, int level,
* simple format string like "%s", followed by the string containing the
* untrusted data.
*/
-AP_DECLARE(void) ap_log_rerror(const char *file, int line, int level,
- apr_status_t status, const request_rec *r,
- const char *fmt, ...)
+#if __STDC_VERSION__ >= 199901L
+/* need additional step to expand APLOG_MARK first */
+#define ap_log_rerror(...) ap_log_rerror__(__VA_ARGS__)
+#define ap_log_rerror__(file, line, level, status, r, ...) \
+ do { if (APLOG_R_IS_LEVEL(r, level)) \
+ ap_log_rerror_(file, line, level, status, r, __VA_ARGS__); \
+ } while(0)
+#else
+#define ap_log_rerror ap_log_rerror_
+#endif
+AP_DECLARE(void) ap_log_rerror_(const char *file, int line, int level,
+ apr_status_t status, const request_rec *r,
+ const char *fmt, ...)
__attribute__((format(printf,6,7)));
/**
@@ -238,9 +280,19 @@ AP_DECLARE(void) ap_log_rerror(const char *file, int line, int level,
* simple format string like "%s", followed by the string containing the
* untrusted data.
*/
-AP_DECLARE(void) ap_log_cerror(const char *file, int line, int level,
- apr_status_t status, const conn_rec *c,
- const char *fmt, ...)
+#if __STDC_VERSION__ >= 199901L
+/* need additional step to expand APLOG_MARK first */
+#define ap_log_cerror(...) ap_log_cerror__(__VA_ARGS__)
+#define ap_log_cerror__(file, line, level, status, c, ...) \
+ do { if (APLOG_C_IS_LEVEL(c, level)) \
+ ap_log_cerror_(file, line, level, status, c, __VA_ARGS__); \
+ } while(0)
+#else
+#define ap_log_cerror ap_log_cerror_
+#endif
+AP_DECLARE(void) ap_log_cerror_(const char *file, int line, int level,
+ apr_status_t status, const conn_rec *c,
+ const char *fmt, ...)
__attribute__((format(printf,6,7)));
/**
diff --git a/server/log.c b/server/log.c
index c3abd5a..0f8e5d2 100644
--- a/server/log.c
+++ b/server/log.c
@@ -721,9 +721,9 @@ static void log_error_core(const char *file, int line, int level,
ap_run_error_log(file, line, level, status, s, r, pool, errstr + errstrlen);
}
-AP_DECLARE(void) ap_log_error(const char *file, int line, int level,
- apr_status_t status, const server_rec *s,
- const char *fmt, ...)
+AP_DECLARE(void) ap_log_error_(const char *file, int line, int level,
+ apr_status_t status, const server_rec *s,
+ const char *fmt, ...)
{
va_list args;
@@ -743,9 +743,9 @@ AP_DECLARE(void) ap_log_perror(const char *file, int line, int level,
va_end(args);
}
-AP_DECLARE(void) ap_log_rerror(const char *file, int line, int level,
- apr_status_t status, const request_rec *r,
- const char *fmt, ...)
+AP_DECLARE(void) ap_log_rerror_(const char *file, int line, int level,
+ apr_status_t status, const request_rec *r,
+ const char *fmt, ...)
{
va_list args;
@@ -772,9 +772,9 @@ AP_DECLARE(void) ap_log_rerror(const char *file, int line, int level,
va_end(args);
}
-AP_DECLARE(void) ap_log_cerror(const char *file, int line, int level,
- apr_status_t status, const conn_rec *c,
- const char *fmt, ...)
+AP_DECLARE(void) ap_log_cerror_(const char *file, int line, int level,
+ apr_status_t status, const conn_rec *c,
+ const char *fmt, ...)
{
va_list args;
diff --git a/include/http_log.h b/include/http_log.h
index ef475a2..e0e0d16 100644
--- a/include/http_log.h
+++ b/include/http_log.h
@@ -39,29 +39,45 @@ extern "C" {
#define LOG_PRIMASK 7
#endif
-#define APLOG_EMERG LOG_EMERG /* system is unusable */
-#define APLOG_ALERT LOG_ALERT /* action must be taken immediately */
-#define APLOG_CRIT LOG_CRIT /* critical conditions */
-#define APLOG_ERR LOG_ERR /* error conditions */
-#define APLOG_WARNING LOG_WARNING /* warning conditions */
-#define APLOG_NOTICE LOG_NOTICE /* normal but significant condition */
-#define APLOG_INFO LOG_INFO /* informational */
-#define APLOG_DEBUG LOG_DEBUG /* debug-level messages */
-
-#define APLOG_LEVELMASK LOG_PRIMASK /* mask off the level value */
+#define APLOG_EMERG LOG_EMERG /* system is unusable */
+#define APLOG_ALERT LOG_ALERT /* action must be taken immediately */
+#define APLOG_CRIT LOG_CRIT /* critical conditions */
+#define APLOG_ERR LOG_ERR /* error conditions */
+#define APLOG_WARNING LOG_WARNING /* warning conditions */
+#define APLOG_NOTICE LOG_NOTICE /* normal but significant condition */
+#define APLOG_INFO LOG_INFO /* informational */
+#define APLOG_DEBUG LOG_DEBUG /* debug-level messages */
+#define APLOG_TRACE1 (LOG_DEBUG + 1) /* trace-level 1 messages */
+#define APLOG_TRACE2 (LOG_DEBUG + 2) /* trace-level 2 messages */
+#define APLOG_TRACE3 (LOG_DEBUG + 3) /* trace-level 3 messages */
+#define APLOG_TRACE4 (LOG_DEBUG + 4) /* trace-level 4 messages */
+#define APLOG_TRACE5 (LOG_DEBUG + 5) /* trace-level 5 messages */
+#define APLOG_TRACE6 (LOG_DEBUG + 6) /* trace-level 6 messages */
+#define APLOG_TRACE7 (LOG_DEBUG + 7) /* trace-level 7 messages */
+#define APLOG_TRACE8 (LOG_DEBUG + 8) /* trace-level 8 messages */
+
+#define APLOG_LEVELMASK ((LOG_PRIMASK << 1) + 1) /* mask off the level value */
#else
-#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 APLOG_LEVELMASK 7 /* mask off the level value */
+#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 APLOG_TRACE1 8 /* trace-level 1 messages */
+#define APLOG_TRACE2 9 /* trace-level 2 messages */
+#define APLOG_TRACE3 10 /* trace-level 3 messages */
+#define APLOG_TRACE4 11 /* trace-level 4 messages */
+#define APLOG_TRACE5 12 /* trace-level 5 messages */
+#define APLOG_TRACE6 13 /* trace-level 6 messages */
+#define APLOG_TRACE7 14 /* trace-level 7 messages */
+#define APLOG_TRACE8 15 /* trace-level 8 messages */
+
+#define APLOG_LEVELMASK 15 /* mask off the level value */
#endif
@@ -104,14 +120,38 @@ extern "C" {
#define APLOGinfo(s) APLOG_IS_LEVEL(s,APLOG_INFO)
#define APLOGdebug(s) APLOG_IS_LEVEL(s,APLOG_DEBUG)
+#define APLOGtrace1(s) APLOG_IS_LEVEL(s,APLOG_TRACE1)
+#define APLOGtrace2(s) APLOG_IS_LEVEL(s,APLOG_TRACE2)
+#define APLOGtrace3(s) APLOG_IS_LEVEL(s,APLOG_TRACE3)
+#define APLOGtrace4(s) APLOG_IS_LEVEL(s,APLOG_TRACE4)
+#define APLOGtrace5(s) APLOG_IS_LEVEL(s,APLOG_TRACE5)
+#define APLOGtrace6(s) APLOG_IS_LEVEL(s,APLOG_TRACE6)
+#define APLOGtrace7(s) APLOG_IS_LEVEL(s,APLOG_TRACE7)
+#define APLOGtrace8(s) APLOG_IS_LEVEL(s,APLOG_TRACE8)
#define APLOG_R_IS_LEVEL(r,level) APLOG_IS_LEVEL(r->server,level)
#define APLOGrinfo(r) APLOG_R_IS_LEVEL(r,APLOG_INFO)
#define APLOGrdebug(r) APLOG_R_IS_LEVEL(r,APLOG_DEBUG)
+#define APLOGrtrace1(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE1)
+#define APLOGrtrace2(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE2)
+#define APLOGrtrace3(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE3)
+#define APLOGrtrace4(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE4)
+#define APLOGrtrace5(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE5)
+#define APLOGrtrace6(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE6)
+#define APLOGrtrace7(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE7)
+#define APLOGrtrace8(r) APLOG_R_IS_LEVEL(r,APLOG_TRACE8)
#define APLOG_C_IS_LEVEL(c,level) APLOG_IS_LEVEL(c->base_server,level)
#define APLOGcinfo(c) APLOG_C_IS_LEVEL(c,APLOG_INFO)
#define APLOGcdebug(c) APLOG_C_IS_LEVEL(c,APLOG_DEBUG)
+#define APLOGctrace1(r) APLOG_C_IS_LEVEL(c,APLOG_TRACE1)
+#define APLOGctrace2(r) APLOG_C_IS_LEVEL(c,APLOG_TRACE2)
+#define APLOGctrace3(r) APLOG_C_IS_LEVEL(c,APLOG_TRACE3)
+#define APLOGctrace4(r) APLOG_C_IS_LEVEL(c,APLOG_TRACE4)
+#define APLOGctrace5(r) APLOG_C_IS_LEVEL(c,APLOG_TRACE5)
+#define APLOGctrace6(r) APLOG_C_IS_LEVEL(c,APLOG_TRACE6)
+#define APLOGctrace7(r) APLOG_C_IS_LEVEL(c,APLOG_TRACE7)
+#define APLOGctrace8(r) APLOG_C_IS_LEVEL(c,APLOG_TRACE8)
extern int AP_DECLARE_DATA ap_default_loglevel;
diff --git a/server/log.c b/server/log.c
index 0f8e5d2..c822562 100644
--- a/server/log.c
+++ b/server/log.c
@@ -134,6 +134,14 @@ static const TRANS priorities[] = {
{"notice", APLOG_NOTICE},
{"info", APLOG_INFO},
{"debug", APLOG_DEBUG},
+ {"trace1", APLOG_TRACE1},
+ {"trace2", APLOG_TRACE2},
+ {"trace3", APLOG_TRACE3},
+ {"trace4", APLOG_TRACE4},
+ {"trace5", APLOG_TRACE5},
+ {"trace6", APLOG_TRACE6},
+ {"trace7", APLOG_TRACE7},
+ {"trace8", APLOG_TRACE8},
{NULL, -1},
};
@@ -606,7 +614,7 @@ static void log_error_core(const char *file, int line, int level,
"[%s] ", priorities[level_and_mask].t_name);
}
- if (file && level_and_mask == APLOG_DEBUG) {
+ if (file && level_and_mask >= APLOG_DEBUG) {
#if defined(_OSD_POSIX) || defined(WIN32) || defined(__MVS__)
char tmp[256];
char *e = strrchr(file, '/');
@@ -714,7 +722,8 @@ static void log_error_core(const char *file, int line, int level,
}
#ifdef HAVE_SYSLOG
else {
- syslog(level_and_mask, "%s", errstr);
+ syslog(level_and_mask < APLOG_DEBUG ? level_and_mask : APLOG_DEBUG,
+ "%s", errstr);
}
#endif
@@ -1130,7 +1139,7 @@ AP_DECLARE(void) ap_close_piped_log(piped_log *pl)
AP_DECLARE(const char *) ap_parse_log_level(const char *str, int *val)
{
char *err = "Loglevel keyword must be one of emerg/alert/crit/error/warn/"
- "notice/info/debug";
+ "notice/info/debug/trace1/.../trace8";
int i = 0;
if (str == NULL)