Respecting default rolling_enabled in plugins. (#7275)
Some plugins indiscriminately enable log rolling without consideration
of the system value. This looks like it is just a mistake that went
unnoticed because we've always had this enabled. This patch changes a
couple plugins to respect the proxy.config.log.rolling_enabled value by
not overwriting it with TSTextLogObjectRollingEnabledSet unless
explicitly configured to do so.
diff --git a/plugins/regex_revalidate/regex_revalidate.c b/plugins/regex_revalidate/regex_revalidate.c
index 4d0ff8b..52a9e97 100644
--- a/plugins/regex_revalidate/regex_revalidate.c
+++ b/plugins/regex_revalidate/regex_revalidate.c
@@ -481,7 +481,6 @@
break;
case 'l':
if (TS_SUCCESS == TSTextLogObjectCreate(optarg, TS_LOG_MODE_ADD_TIMESTAMP, &pstate->log)) {
- TSTextLogObjectRollingEnabledSet(pstate->log, 1);
TSTextLogObjectRollingIntervalSecSet(pstate->log, LOG_ROLL_INTERVAL);
TSTextLogObjectRollingOffsetHrSet(pstate->log, LOG_ROLL_OFFSET);
}
diff --git a/plugins/tcpinfo/tcpinfo.cc b/plugins/tcpinfo/tcpinfo.cc
index 0c9d07f..ca73cb0 100644
--- a/plugins/tcpinfo/tcpinfo.cc
+++ b/plugins/tcpinfo/tcpinfo.cc
@@ -337,7 +337,7 @@
const char *filename = "tcpinfo";
TSCont cont;
unsigned int hooks = 0;
- unsigned int rolling_enabled = 1;
+ int rolling_enabled = -1;
unsigned int rolling_interval_sec = 86400;
unsigned int rolling_offset_hr = 0;
unsigned int rolling_size = 1024;
@@ -379,7 +379,8 @@
case 'e':
i = strtoul(optarg, &endptr, 10);
if (*endptr != '\0' || i > 3) {
- TSError("[tcpinfo] invalid rolling-enabled argument, '%s', using default of %d", optarg, rolling_enabled);
+ TSError("[tcpinfo] invalid rolling-enabled argument, '%s', using the system's proxy.config.log.rolling_enabled value",
+ optarg);
} else {
rolling_enabled = i;
}
@@ -424,20 +425,26 @@
TSDebug("tcpinfo", "sample: %d", config->sample);
TSDebug("tcpinfo", "log filename: %s", filename);
TSDebug("tcpinfo", "log_level: %u", config->log_level);
+ TSDebug("tcpinfo", "rolling_enabled: %d", rolling_enabled);
TSDebug("tcpinfo", "hook mask: 0x%x", hooks);
if (TSTextLogObjectCreate(filename, TS_LOG_MODE_ADD_TIMESTAMP, &config->log) != TS_SUCCESS) {
TSError("[tcpinfo] failed to create log file '%s'", filename);
return;
}
- if (TSTextLogObjectRollingEnabledSet(config->log, rolling_enabled) != TS_SUCCESS) {
- TSError("[tcpinfo] failed to enable log file rolling to: '%d'", rolling_enabled);
- return;
+ if (rolling_enabled == -1) {
+ // The user either did not provide a value or the value they provided was
+ // invalid.
+ TSDebug("tcpinfo", "Using system default value of proxy.config.log.rolling_enabled ");
} else {
- TSTextLogObjectRollingIntervalSecSet(config->log, rolling_interval_sec);
- TSTextLogObjectRollingOffsetHrSet(config->log, rolling_offset_hr);
- TSTextLogObjectRollingSizeMbSet(config->log, rolling_size);
+ if (TSTextLogObjectRollingEnabledSet(config->log, rolling_enabled) != TS_SUCCESS) {
+ TSError("[tcpinfo] failed to enable log file rolling to: '%d'", rolling_enabled);
+ return;
+ }
}
+ TSTextLogObjectRollingIntervalSecSet(config->log, rolling_interval_sec);
+ TSTextLogObjectRollingOffsetHrSet(config->log, rolling_offset_hr);
+ TSTextLogObjectRollingSizeMbSet(config->log, rolling_size);
TSTextLogObjectHeaderSet(config->log, tcpi_headers[config->log_level - 1]);