Added XML warn/error output to debug log. See #519.

This commit is contained in:
brectanus
2008-08-15 19:58:02 +00:00
parent 458fe8423c
commit 5298e29540
8 changed files with 682 additions and 2 deletions

View File

@@ -245,6 +245,7 @@ void internal_log(request_rec *r, directory_config *dcfg, modsec_rec *msr,
apr_size_t nbytes, nbytes_written;
apr_file_t *debuglog_fd = NULL;
int filter_debug_level = 0;
int str2len;
char str1[1024] = "";
char str2[1256] = "";
@@ -262,13 +263,20 @@ void internal_log(request_rec *r, directory_config *dcfg, modsec_rec *msr,
*/
if ((level > 3)&&( (debuglog_fd == NULL) || (level > filter_debug_level) )) return;
/* Construct the message. */
/* Construct the message (leaving a byte left for a newline if needed). */
apr_vsnprintf(str1, sizeof(str1), text, ap);
apr_snprintf(str2, sizeof(str2), "[%s] [%s/sid#%pp][rid#%pp][%s][%d] %s\n",
str2len = apr_snprintf(str2, sizeof(str2)-1,
"[%s] [%s/sid#%pp][rid#%pp][%s][%d] %s",
current_logtime(msr->mp), ap_get_server_name(r), (r->server),
r, ((r->uri == NULL) ? "" : log_escape_nq(msr->mp, r->uri)),
level, str1);
/* Add a newline if there is not one already (needed for msr_log_*) */
if (str2[str2len - 1] != '\n') {
str2[str2len] = '\n';
str2[str2len + 1] = '\0';
}
/* Write to the debug log. */
if ((debuglog_fd != NULL)&&(level <= filter_debug_level)) {
nbytes = strlen(str2);
@@ -321,6 +329,33 @@ void msr_log(modsec_rec *msr, int level, const char *text, ...) {
}
/**
* Logs one message at level 3 to the debug log and to the
* Apache error log. This is intended for error callbacks.
*/
void msr_log_error(modsec_rec *msr, const char *text, ...) {
const char *str = text;
va_list ap;
va_start(ap, text);
internal_log(msr->r, msr->txcfg, msr, 3, str, ap);
va_end(ap);
}
/**
* Logs one message at level 4 to the debug log and to the
* Apache error log. This is intended for warning callbacks.
*/
void msr_log_warn(modsec_rec *msr, const char *text, ...) {
const char *str = text;
va_list ap;
va_start(ap, text);
internal_log(msr->r, msr->txcfg, msr, 4, str, ap);
va_end(ap);
}
/**
* Converts an Apache error log message into one line of text.
*/