Skip to content

Commit

Permalink
Allow "unlimited" value
Browse files Browse the repository at this point in the history
  • Loading branch information
lordgamez committed Aug 3, 2023
1 parent baa69e9 commit 9133ea4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion conf/minifi-log.properties
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ logger.org::apache::nifi::minifi=INFO,rolling
#compression.cached.log.max.size=8 MB
#compression.compressed.log.max.size=8 MB

## Maximum length of a MiNiFi log entry, use -1 for unlimited
## Maximum length of a MiNiFi log entry (use "unlimited" or "-1" for no limit)
#max.log.entry.length=1024
2 changes: 1 addition & 1 deletion docker/conf/minifi-log.properties
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ logger.org::apache::nifi::minifi=INFO,stderr
#compression.cached.log.max.size=8 MB
#compression.compressed.log.max.size=8 MB

## Maximum length of a MiNiFi log entry, use -1 for unlimited
## Maximum length of a MiNiFi log entry (use "unlimited" or "-1" for no limit)
#max.log.entry.length=1024
4 changes: 3 additions & 1 deletion libminifi/include/core/logging/LoggerConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ struct LoggerNamespace {
inline std::optional<std::string> formatId(std::optional<utils::Identifier> opt_id) {
return opt_id | utils::map([](auto id) { return " (" + std::string(id.to_string()) + ")"; });
}

constexpr std::string_view UNLIMITED_LOG_ENTRY_LENGTH = "unlimited";
} // namespace internal

class LoggerConfiguration {
Expand Down Expand Up @@ -161,7 +163,7 @@ class LoggerConfiguration {
std::shared_ptr<LoggerImpl> logger_ = nullptr;
std::shared_ptr<LoggerControl> controller_;
std::unordered_set<std::shared_ptr<AlertSink>> alert_sinks_;
std::optional<uint64_t> max_log_entry_length_;
std::optional<int> max_log_entry_length_;
bool shorten_names_ = false;
bool include_uuid_ = true;
};
Expand Down
2 changes: 1 addition & 1 deletion libminifi/src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const std::unordered_map<std::string_view, gsl::not_null<const core::PropertyVal
{Configuration::nifi_log_logger_root, gsl::make_not_null(&core::StandardPropertyTypes::VALID_TYPE)},
{Configuration::nifi_log_compression_cached_log_max_size, gsl::make_not_null(&core::StandardPropertyTypes::DATA_SIZE_TYPE)},
{Configuration::nifi_log_compression_compressed_log_max_size, gsl::make_not_null(&core::StandardPropertyTypes::DATA_SIZE_TYPE)},
{Configuration::nifi_log_max_log_entry_length, gsl::make_not_null(&core::StandardPropertyTypes::UNSIGNED_INT_TYPE)},
{Configuration::nifi_log_max_log_entry_length, gsl::make_not_null(&core::StandardPropertyTypes::VALID_TYPE)},
{Configuration::nifi_log_alert_url, gsl::make_not_null(&core::StandardPropertyTypes::VALID_TYPE)},
{Configuration::nifi_log_alert_ssl_context_service, gsl::make_not_null(&core::StandardPropertyTypes::VALID_TYPE)},
{Configuration::nifi_log_alert_batch_size, gsl::make_not_null(&core::StandardPropertyTypes::VALID_TYPE)},
Expand Down
10 changes: 7 additions & 3 deletions libminifi/src/core/logging/LoggerConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,13 @@ void LoggerConfiguration::initialize(const std::shared_ptr<LoggerProperties> &lo

if (const auto max_log_entry_length_str = logger_properties->getString("max.log.entry.length")) {
try {
max_log_entry_length_ = std::stoull(*max_log_entry_length_str);
if (internal::UNLIMITED_LOG_ENTRY_LENGTH == *max_log_entry_length_str) {
max_log_entry_length_ = -1;
} else {
max_log_entry_length_ = std::stoull(*max_log_entry_length_str);
}
} catch (const std::exception& ex) {
logger_->log_debug("Parsing max log entry length property failed with the following exception: %s", ex.what());
logger_->log_error("Parsing max log entry length property failed with the following exception: %s", ex.what());
}
}

Expand Down Expand Up @@ -176,7 +180,7 @@ std::shared_ptr<Logger> LoggerConfiguration::getLogger(std::string_view name, co
std::shared_ptr<LoggerImpl> result = std::make_shared<LoggerImpl>(adjusted_name, id_if_enabled, controller_, get_logger(logger_, root_namespace_, adjusted_name, formatter_));
loggers.push_back(result);
if (max_log_entry_length_) {
result->set_max_log_size(*max_log_entry_length_);
result->set_max_log_size(gsl::narrow<int>(*max_log_entry_length_));
}
return result;
}
Expand Down
9 changes: 7 additions & 2 deletions libminifi/test/unit/LoggerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,15 @@ TEST_CASE("Setting max log entry length to a size larger than the internal buffe
REQUIRE(logs.find(expected_log) != std::string::npos);
}

TEST_CASE("Setting max log entry length to negative number results in unlimited log entry size", "[ttl15]") {
TEST_CASE("Setting max log entry length to unlimited results in unlimited log entry size", "[ttl15]") {
auto& log_config = logging::LoggerConfiguration::getConfiguration();
auto properties = std::make_shared<logging::LoggerProperties>();
properties->set("max.log.entry.length", "-1");
SECTION("Use unlimited value") {
properties->set("max.log.entry.length", "unlimited");
}
SECTION("Use -1 value") {
properties->set("max.log.entry.length", "-1");
}
properties->set("logger.root", "INFO");
log_config.initialize(properties);
auto logger = log_config.getLogger("SetMaxLogEntryLengthTestLogger");
Expand Down

0 comments on commit 9133ea4

Please sign in to comment.