Skip to content

Commit 4771223

Browse files
committed
Also supress info error log messages when modsecurity_error_log is set to off
1 parent d5b5ebf commit 4771223

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/ngx_http_modsecurity_module.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ ngx_http_modsecurity_create_ctx(ngx_http_request_t *r)
280280
ngx_http_modsecurity_ctx_t *ctx;
281281
ngx_http_modsecurity_conf_t *mcf;
282282
ngx_http_modsecurity_main_conf_t *mmcf;
283+
ngx_log_t *log = NULL;
283284

284285
ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_modsecurity_ctx_t));
285286
if (ctx == NULL)
@@ -295,14 +296,19 @@ ngx_http_modsecurity_create_ctx(ngx_http_request_t *r)
295296

296297
dd("creating transaction with the following rules: '%p' -- ms: '%p'", mcf->rules_set, mmcf->modsec);
297298

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+
298304
if (mcf->transaction_id) {
299305
if (ngx_http_complex_value(r, mcf->transaction_id, &s) != NGX_OK) {
300306
return NGX_CONF_ERROR;
301307
}
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);
303309

304310
} 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);
306312
}
307313

308314
dd("transaction created");

0 commit comments

Comments
 (0)