Skip to content

Commit 3a048ee

Browse files
michaelgranzow-aviFelipe Zimmerle
authored andcommitted
Support --enable-debug-logs=no option of configure script (#2)
* Support --enable-debug-logs=no option of configure script * Undo unintended white space changes * Undo more unintended white space changes * Address review comments - thanks Mirko * Address more review comments - thanks Mirko
1 parent 1d3c4c6 commit 3a048ee

File tree

22 files changed

+305
-4
lines changed

22 files changed

+305
-4
lines changed

src/actions/ctl/rule_engine.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ bool RuleEngine::evaluate(Rule *rule, Transaction *transaction) {
5050
a << modsecurity::RulesProperties::ruleEngineStateString(m_ruleEngine);
5151
a << " as requested by a ctl:ruleEngine action";
5252

53+
#ifndef NO_LOGS
5354
transaction->debug(8, a.str());
55+
#endif
5456

5557
transaction->m_secRuleEngine = m_ruleEngine;
5658
return true;

src/actions/disruptive/allow.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ bool Allow::init(std::string *error) {
4949

5050

5151
bool Allow::evaluate(Rule *rule, Transaction *transaction) {
52+
#ifndef NO_LOGS
5253
transaction->debug(4, "Dropping the evaluation of upcoming rules " \
5354
"in favor of an `allow' action of type: " \
5455
+ allowTypeToName(m_allowType));
56+
#endif
5557

5658
transaction->m_allowType = m_allowType;
5759

src/actions/disruptive/block.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ namespace disruptive {
3232

3333
bool Block::evaluate(Rule *rule, Transaction *transaction,
3434
std::shared_ptr<RuleMessage> rm) {
35+
#ifndef NO_LOGS
3536
transaction->debug(8, "Marking request as disruptive.");
37+
#endif
3638

3739
for (Action *a : transaction->m_rules->m_defaultActions[rule->m_phase]) {
3840
if (a->isDisruptive() == false) {

src/actions/disruptive/pass.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ bool Pass::evaluate(Rule *rule, Transaction *transaction,
3333
intervention::free(&transaction->m_it);
3434
intervention::reset(&transaction->m_it);
3535

36+
#ifndef NO_LOGS
3637
transaction->debug(8, "Running action pass");
38+
#endif
3739

3840
return true;
3941
}

src/actions/init_col.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ bool InitCol::evaluate(Rule *rule, Transaction *t) {
7171
return false;
7272
}
7373

74+
#ifndef NO_LOGS
7475
t->debug(5, "Collection `" + m_collection_key + "' initialized with " \
7576
"value: " + collectionName);
77+
#endif
7678

7779
return true;
7880
}

src/actions/log.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ namespace actions {
3030

3131
bool Log::evaluate(Rule *rule, Transaction *transaction,
3232
std::shared_ptr<RuleMessage> rm) {
33+
#ifndef NO_LOGS
3334
transaction->debug(9, "Saving transaction to logs");
35+
#endif
3436
rm->m_saveMessage = true;
3537
return true;
3638
}

src/actions/msg.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ bool Msg::evaluate(Rule *rule, Transaction *transaction,
5151
std::shared_ptr<RuleMessage> rm) {
5252
std::string msg = data(transaction);
5353
rm->m_message = msg;
54+
#ifndef NO_LOGS
5455
transaction->debug(9, "Saving msg: " + msg);
56+
#endif
5557

5658
transaction->m_collections.storeOrUpdateFirst("RULE:msg", msg);
5759

src/audit_log/audit_log.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,26 +282,34 @@ bool AuditLog::saveIfRelevant(Transaction *transaction, int parts) {
282282
if ((m_status == RelevantOnlyAuditLogStatus
283283
&& this->isRelevant(transaction->m_httpCodeReturned) == false)
284284
&& saveAnyway == false) {
285+
#ifndef NO_LOGS
285286
transaction->debug(9, "Return code `" +
286287
std::to_string(transaction->m_httpCodeReturned) + "'" \
287288
" is not interesting to audit logs, relevant code(s): `" +
288289
m_relevant + "'.");
290+
#endif
289291

290292
return false;
291293
}
292294

293295
if (parts == -1) {
294296
parts = m_parts;
295297
}
298+
#ifndef NO_LOGS
296299
transaction->debug(5, "Saving this request as part " \
297300
"of the audit logs.");
301+
#endif
298302
if (m_writer == NULL) {
303+
#ifndef NO_LOGS
299304
transaction->debug(1, "Internal error, audit log writer is null");
305+
#endif
300306
} else {
301307
std::string error;
302308
bool a = m_writer->write(transaction, parts, &error);
303309
if (a == false) {
310+
#ifndef NO_LOGS
304311
transaction->debug(1, "Cannot save the audit log: " + error);
312+
#endif
305313
return false;
306314
}
307315
}

src/audit_log/writer/https.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ bool Https::init(std::string *error) {
4747

4848
bool Https::write(Transaction *transaction, int parts, std::string *error) {
4949
Utils::HttpsClient m_http_client;
50+
#ifndef NO_LOGS
5051
transaction->debug(7, "Sending logs to: " + m_audit->m_path1);
52+
#endif
5153

5254
std::string log = transaction->toJSON(parts);
5355
m_http_client.setRequestType("application/json");

src/macro_expansion.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,14 @@ std::string MacroExpansion::expand(const std::string& input,
301301
}
302302
}
303303

304+
#ifndef NO_LOGS
304305
if (variableValue) {
305306
transaction->debug(6, "Resolving: " + variable + " to: " +
306307
*variableValue);
307308
} else {
308309
transaction->debug(6, "Resolving: " + variable + " to: NULL");
309310
}
311+
#endif
310312
res.erase(start, end - start + 1);
311313
if (res[start] == '%') {
312314
res.erase(start, 1);

0 commit comments

Comments
 (0)