@@ -280,6 +280,7 @@ ngx_http_modsecurity_create_ctx(ngx_http_request_t *r)
280
280
ngx_http_modsecurity_ctx_t * ctx ;
281
281
ngx_http_modsecurity_conf_t * mcf ;
282
282
ngx_http_modsecurity_main_conf_t * mmcf ;
283
+ ngx_log_t * log = NULL ;
283
284
284
285
ctx = ngx_pcalloc (r -> pool , sizeof (ngx_http_modsecurity_ctx_t ));
285
286
if (ctx == NULL )
@@ -295,14 +296,19 @@ ngx_http_modsecurity_create_ctx(ngx_http_request_t *r)
295
296
296
297
dd ("creating transaction with the following rules: '%p' -- ms: '%p'" , mcf -> rules_set , mmcf -> modsec );
297
298
299
+ // if logging to error log is disabled, log will be NULL and nothing will be logged by `ngx_http_modsecurity_log`
300
+ if (mcf -> error_log ) {
301
+ log = r -> connection -> log ;
302
+ }
303
+
298
304
if (mcf -> transaction_id ) {
299
305
if (ngx_http_complex_value (r , mcf -> transaction_id , & s ) != NGX_OK ) {
300
306
return NGX_CONF_ERROR ;
301
307
}
302
- ctx -> modsec_transaction = msc_new_transaction_with_id (mmcf -> modsec , mcf -> rules_set , (char * ) s .data , r -> connection -> log );
308
+ ctx -> modsec_transaction = msc_new_transaction_with_id (mmcf -> modsec , mcf -> rules_set , (char * ) s .data , log );
303
309
304
310
} else {
305
- ctx -> modsec_transaction = msc_new_transaction (mmcf -> modsec , mcf -> rules_set , r -> connection -> log );
311
+ ctx -> modsec_transaction = msc_new_transaction (mmcf -> modsec , mcf -> rules_set , log );
306
312
}
307
313
308
314
dd ("transaction created" );
0 commit comments