|
|
@ -64,8 +64,9 @@ class AutoRollLoggerTest : public testing::Test { |
|
|
|
ASSERT_TRUE(system(deleteDbDirCmd.c_str()) == 0); |
|
|
|
ASSERT_TRUE(system(deleteDbDirCmd.c_str()) == 0); |
|
|
|
|
|
|
|
|
|
|
|
std::string testDir(kTestDir); |
|
|
|
std::string testDir(kTestDir); |
|
|
|
std::replace_if(testDir.begin(), testDir.end(), |
|
|
|
std::replace_if( |
|
|
|
[](char ch) { return ch == '/'; }, '\\'); |
|
|
|
testDir.begin(), testDir.end(), [](char ch) { return ch == '/'; }, |
|
|
|
|
|
|
|
'\\'); |
|
|
|
std::string deleteCmd = "if exist " + testDir + " rd /s /q " + testDir; |
|
|
|
std::string deleteCmd = "if exist " + testDir + " rd /s /q " + testDir; |
|
|
|
#else |
|
|
|
#else |
|
|
|
std::string deleteCmd = "rm -rf " + kTestDir + " " + kTestDbDir; |
|
|
|
std::string deleteCmd = "rm -rf " + kTestDir + " " + kTestDbDir; |
|
|
@ -207,8 +208,8 @@ TEST_F(AutoRollLoggerTest, RollLogFileBySize) { |
|
|
|
size_t log_max_size = 1024 * 5; |
|
|
|
size_t log_max_size = 1024 * 5; |
|
|
|
size_t keep_log_file_num = 10; |
|
|
|
size_t keep_log_file_num = 10; |
|
|
|
|
|
|
|
|
|
|
|
AutoRollLogger logger(FileSystem::Default(), SystemClock::Default(), |
|
|
|
AutoRollLogger logger(FileSystem::Default(), SystemClock::Default(), kTestDir, |
|
|
|
kTestDir, "", log_max_size, 0, keep_log_file_num); |
|
|
|
"", log_max_size, 0, keep_log_file_num); |
|
|
|
|
|
|
|
|
|
|
|
RollLogFileBySizeTest(&logger, log_max_size, |
|
|
|
RollLogFileBySizeTest(&logger, log_max_size, |
|
|
|
kSampleMessage + ":RollLogFileBySize"); |
|
|
|
kSampleMessage + ":RollLogFileBySize"); |
|
|
@ -321,8 +322,7 @@ TEST_F(AutoRollLoggerTest, CreateLoggerFromOptions) { |
|
|
|
AutoRollLogger* auto_roll_logger = |
|
|
|
AutoRollLogger* auto_roll_logger = |
|
|
|
dynamic_cast<AutoRollLogger*>(logger.get()); |
|
|
|
dynamic_cast<AutoRollLogger*>(logger.get()); |
|
|
|
ASSERT_TRUE(auto_roll_logger); |
|
|
|
ASSERT_TRUE(auto_roll_logger); |
|
|
|
RollLogFileBySizeTest( |
|
|
|
RollLogFileBySizeTest(auto_roll_logger, options.max_log_file_size, |
|
|
|
auto_roll_logger, options.max_log_file_size, |
|
|
|
|
|
|
|
kSampleMessage + ":CreateLoggerFromOptions - size"); |
|
|
|
kSampleMessage + ":CreateLoggerFromOptions - size"); |
|
|
|
|
|
|
|
|
|
|
|
// Only roll by Time
|
|
|
|
// Only roll by Time
|
|
|
@ -331,8 +331,7 @@ TEST_F(AutoRollLoggerTest, CreateLoggerFromOptions) { |
|
|
|
options.max_log_file_size = 0; |
|
|
|
options.max_log_file_size = 0; |
|
|
|
options.log_file_time_to_roll = 2; |
|
|
|
options.log_file_time_to_roll = 2; |
|
|
|
ASSERT_OK(CreateLoggerFromOptions(kTestDir, options, &logger)); |
|
|
|
ASSERT_OK(CreateLoggerFromOptions(kTestDir, options, &logger)); |
|
|
|
auto_roll_logger = |
|
|
|
auto_roll_logger = dynamic_cast<AutoRollLogger*>(logger.get()); |
|
|
|
dynamic_cast<AutoRollLogger*>(logger.get()); |
|
|
|
|
|
|
|
RollLogFileByTimeTest(options.env->GetFileSystem(), nsc, auto_roll_logger, |
|
|
|
RollLogFileByTimeTest(options.env->GetFileSystem(), nsc, auto_roll_logger, |
|
|
|
options.log_file_time_to_roll, |
|
|
|
options.log_file_time_to_roll, |
|
|
|
kSampleMessage + ":CreateLoggerFromOptions - time"); |
|
|
|
kSampleMessage + ":CreateLoggerFromOptions - time"); |
|
|
@ -342,8 +341,7 @@ TEST_F(AutoRollLoggerTest, CreateLoggerFromOptions) { |
|
|
|
options.max_log_file_size = 1024 * 5; |
|
|
|
options.max_log_file_size = 1024 * 5; |
|
|
|
options.log_file_time_to_roll = 2; |
|
|
|
options.log_file_time_to_roll = 2; |
|
|
|
ASSERT_OK(CreateLoggerFromOptions(kTestDir, options, &logger)); |
|
|
|
ASSERT_OK(CreateLoggerFromOptions(kTestDir, options, &logger)); |
|
|
|
auto_roll_logger = |
|
|
|
auto_roll_logger = dynamic_cast<AutoRollLogger*>(logger.get()); |
|
|
|
dynamic_cast<AutoRollLogger*>(logger.get()); |
|
|
|
|
|
|
|
RollLogFileBySizeTest(auto_roll_logger, options.max_log_file_size, |
|
|
|
RollLogFileBySizeTest(auto_roll_logger, options.max_log_file_size, |
|
|
|
kSampleMessage + ":CreateLoggerFromOptions - both"); |
|
|
|
kSampleMessage + ":CreateLoggerFromOptions - both"); |
|
|
|
RollLogFileByTimeTest(options.env->GetFileSystem(), nsc, auto_roll_logger, |
|
|
|
RollLogFileByTimeTest(options.env->GetFileSystem(), nsc, auto_roll_logger, |
|
|
@ -602,7 +600,6 @@ TEST_F(AutoRollLoggerTest, LogHeaderTest) { |
|
|
|
// test_num == 0 -> standard call to Header()
|
|
|
|
// test_num == 0 -> standard call to Header()
|
|
|
|
// test_num == 1 -> call to Log() with InfoLogLevel::HEADER_LEVEL
|
|
|
|
// test_num == 1 -> call to Log() with InfoLogLevel::HEADER_LEVEL
|
|
|
|
for (int test_num = 0; test_num < 2; test_num++) { |
|
|
|
for (int test_num = 0; test_num < 2; test_num++) { |
|
|
|
|
|
|
|
|
|
|
|
InitTestDb(); |
|
|
|
InitTestDb(); |
|
|
|
|
|
|
|
|
|
|
|
AutoRollLogger logger(FileSystem::Default(), SystemClock::Default(), |
|
|
|
AutoRollLogger logger(FileSystem::Default(), SystemClock::Default(), |
|
|
@ -640,7 +637,7 @@ TEST_F(AutoRollLoggerTest, LogHeaderTest) { |
|
|
|
|
|
|
|
|
|
|
|
const auto oldfiles = GetOldFileNames(newfname); |
|
|
|
const auto oldfiles = GetOldFileNames(newfname); |
|
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(oldfiles.size(), (size_t) 2); |
|
|
|
ASSERT_EQ(oldfiles.size(), (size_t)2); |
|
|
|
|
|
|
|
|
|
|
|
for (auto& oldfname : oldfiles) { |
|
|
|
for (auto& oldfname : oldfiles) { |
|
|
|
// verify that the files rolled over
|
|
|
|
// verify that the files rolled over
|
|
|
@ -658,8 +655,8 @@ TEST_F(AutoRollLoggerTest, LogFileExistence) { |
|
|
|
// Replace all slashes in the path so windows CompSpec does not
|
|
|
|
// Replace all slashes in the path so windows CompSpec does not
|
|
|
|
// become confused
|
|
|
|
// become confused
|
|
|
|
std::string testDir(kTestDir); |
|
|
|
std::string testDir(kTestDir); |
|
|
|
std::replace_if(testDir.begin(), testDir.end(), |
|
|
|
std::replace_if( |
|
|
|
[](char ch) { return ch == '/'; }, '\\'); |
|
|
|
testDir.begin(), testDir.end(), [](char ch) { return ch == '/'; }, '\\'); |
|
|
|
std::string deleteCmd = "if exist " + testDir + " rd /s /q " + testDir; |
|
|
|
std::string deleteCmd = "if exist " + testDir + " rd /s /q " + testDir; |
|
|
|
#else |
|
|
|
#else |
|
|
|
std::string deleteCmd = "rm -rf " + kTestDir; |
|
|
|
std::string deleteCmd = "rm -rf " + kTestDir; |
|
|
|