@@ -284,12 +284,27 @@ static void internal_log_ex(request_rec *r, directory_config *dcfg, modsec_rec *
284
284
}
285
285
else hostname = "" ;
286
286
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
288
290
ap_log_rerror (APLOG_MARK , APLOG_ERR | APLOG_NOERRNO , 0 , r ,
289
291
"ModSecurity: %s%s [uri \"%s\"]%s" , str1 , hostname , log_escape (msr -> mp , r -> uri ), unique_id );
290
- #else
292
+ #else
291
293
ap_log_error (APLOG_MARK , APLOG_ERR | APLOG_NOERRNO , 0 , r -> server ,
292
294
"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
293
308
#endif
294
309
295
310
/* Add this message to the list. */
0 commit comments