Changes debuglogs schema to avoid unecessary str allocation

This commit is contained in:
Felipe Zimmerle
2018-10-19 16:56:33 -03:00
parent 23e0d35d2d
commit ef7f65db90
57 changed files with 1100 additions and 1374 deletions

View File

@@ -292,9 +292,7 @@ bool AuditLog::saveIfRelevant(Transaction *transaction) {
bool AuditLog::saveIfRelevant(Transaction *transaction, int parts) {
bool saveAnyway = false;
if (m_status == OffAuditLogStatus || m_status == NotSetLogStatus) {
#ifndef NO_LOGS
transaction->debug(5, "Audit log engine was not set.");
#endif
ms_dbg_a(transaction, 5, "Audit log engine was not set.");
return true;
}
@@ -308,12 +306,10 @@ bool AuditLog::saveIfRelevant(Transaction *transaction, int parts) {
if ((m_status == RelevantOnlyAuditLogStatus
&& this->isRelevant(transaction->m_httpCodeReturned) == false)
&& saveAnyway == false) {
#ifndef NO_LOGS
transaction->debug(9, "Return code `" +
ms_dbg_a(transaction, 9, "Return code `" +
std::to_string(transaction->m_httpCodeReturned) + "'" \
" is not interesting to audit logs, relevant code(s): `" +
m_relevant + "'.");
#endif
return false;
}
@@ -321,21 +317,15 @@ bool AuditLog::saveIfRelevant(Transaction *transaction, int parts) {
if (parts == -1) {
parts = m_parts;
}
#ifndef NO_LOGS
transaction->debug(5, "Saving this request as part " \
ms_dbg_a(transaction, 5, "Saving this request as part " \
"of the audit logs.");
#endif
if (m_writer == NULL) {
#ifndef NO_LOGS
transaction->debug(1, "Internal error, audit log writer is null");
#endif
ms_dbg_a(transaction, 1, "Internal error, audit log writer is null");
} else {
std::string error;
bool a = m_writer->write(transaction, parts, &error);
if (a == false) {
#ifndef NO_LOGS
transaction->debug(1, "Cannot save the audit log: " + error);
#endif
ms_dbg_a(transaction, 1, "Cannot save the audit log: " + error);
return false;
}
}

View File

@@ -27,10 +27,12 @@
#include "modsecurity/audit_log.h"
#include "modsecurity/transaction.h"
#include "modsecurity/rules.h"
#include "src/utils/md5.h"
#include "src/utils/https_client.h"
namespace modsecurity {
namespace audit_log {
namespace writer {
@@ -47,9 +49,7 @@ bool Https::init(std::string *error) {
bool Https::write(Transaction *transaction, int parts, std::string *error) {
Utils::HttpsClient m_http_client;
#ifndef NO_LOGS
transaction->debug(7, "Sending logs to: " + m_audit->m_path1);
#endif
ms_dbg_a(transaction, 7, "Sending logs to: " + m_audit->m_path1);
std::string log = transaction->toJSON(parts);
m_http_client.setRequestType("application/json");