Skip to content

Commit 9bc3300

Browse files
authored
Merge pull request #3374 from RedXanadu/fix_standalone_error_logging
Fix error logging for standalone module
2 parents 377629b + 0c7dadc commit 9bc3300

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

apache2/apache2_util.c

+17-2
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,27 @@ static void internal_log_ex(request_rec *r, directory_config *dcfg, modsec_rec *
284284
}
285285
else hostname = "";
286286

287-
#if AP_SERVER_MAJORVERSION_NUMBER > 1 && AP_SERVER_MINORVERSION_NUMBER > 2
287+
/* Non-standalone modules use amended format string for logging */
288+
#if !(defined(VERSION_STANDALONE))
289+
#if AP_SERVER_MAJORVERSION_NUMBER > 1 && AP_SERVER_MINORVERSION_NUMBER > 2
288290
ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
289291
"ModSecurity: %s%s [uri \"%s\"]%s", str1, hostname, log_escape(msr->mp, r->uri), unique_id);
290-
#else
292+
#else
291293
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r->server,
292294
"ModSecurity: %s%s [uri \"%s\"]%s", str1, hostname, log_escape(msr->mp, r->uri), unique_id);
295+
#endif
296+
/* Standalone module must use original format string for logging with explicit
297+
* "[client %s]" to log client IP address (no Apache to implicitly add this) */
298+
#else
299+
#if AP_SERVER_MAJORVERSION_NUMBER > 1 && AP_SERVER_MINORVERSION_NUMBER > 2
300+
ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
301+
"[client %s] ModSecurity: %s%s [uri \"%s\"]%s", r->useragent_ip ? r->useragent_ip : r->connection->client_ip, str1,
302+
hostname, log_escape(msr->mp, r->uri), unique_id);
303+
#else
304+
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r->server,
305+
"[client %s] ModSecurity: %s%s [uri \"%s\"]%s", msr->remote_addr ? msr->remote_addr : r->connection->remote_ip, str1,
306+
hostname, log_escape(msr->mp, r->uri), unique_id);
307+
#endif
293308
#endif
294309

295310
/* Add this message to the list. */

0 commit comments

Comments
 (0)