++i;
}
std::array<std::string, 3> const suffixes({"", "KB", "MB"});
- std::string const maxFileSize(to_string(maxsize) + suffixes[i]);
- properties.setProperty("MaxFileSize", maxFileSize);
+ std::string const max_file_size(to_string(maxsize) + suffixes[i]);
+
+ // If maxsize is still past INT_MAX, it will overflow in log4cplus,
+ // so stop here instead.
+ if (std::numeric_limits<int32_t>::max() < maxsize) {
+ isc_throw(BadValue, "expected maxsize < "
+ << std::numeric_limits<int32_t>::max()
+ << "MB , but instead got "
+ << max_file_size);
+ }
+ properties.setProperty("MaxFileSize", max_file_size);
properties.setProperty("MaxBackupIndex",
lexical_cast<string>(opt.maxver));
properties.setProperty("ImmediateFlush", opt.flush ? "true" : "false");
#include <log/logger_specification.h>
#include <log/message_initializer.h>
#include <log/output_option.h>
-
#include <log/tests/tempdir.h>
+#include <testutils/gtest_utils.h>
#include <sys/types.h>
#include <regex.h>
opt->maxsize = SIZE_LIMIT; // Bytes
opt->maxver = 2;
- // The current current output file does not exist (the creation of file_spec
+ // The current output file does not exist (the creation of file_spec
// ensures that. Check that previous versions don't either.
vector<string> prev_name;
for (int i = 0; i < 3; ++i) {
}
}
+// Check if an exception is thrown if maxsize is too large.
+TEST_F(LoggerManagerTest, TooLargeMaxsize) {
+ // Set up the name of the file.
+ SpecificationForFileLogger file_spec;
+ LoggerSpecification& spec(file_spec.getSpecification());
+
+ // UINT64_MAX should be large enough.
+ LoggerSpecification::iterator opt = spec.begin();
+ EXPECT_TRUE(opt != spec.end());
+ opt->maxsize = std::numeric_limits<uint64_t>::max(); // bytes
+
+ // Set up the file logger.
+ LoggerManager manager;
+ EXPECT_THROW_MSG(manager.process(spec), BadValue,
+ "expected maxsize < 2147483647MB , but instead got "
+ "18446744073709MB");
+}
+
namespace { // begin unnamed namespace
// When we begin to use C++11, we could replace use of POSIX API with
ASSERT_NO_THROW(parser.parseConfiguration(config));
ASSERT_NO_THROW(server_cfg->applyLoggingCfg());
- EXPECT_EQ(server_cfg->getLoggingInfo()[0].destinations_[0].maxsize_, expected_maxsize);
+ EXPECT_EQ(server_cfg->getLoggingInfo()[0].destinations_[0].maxsize_,
+ expected_maxsize);
}
// Test that maxsize can be configured with high values.