Introduce InfoLogLevel::HEADER_LEVEL
Summary: Introduced a new category in the enum InfoLogLevel in env.h. Modifed Log() in env.cc to use the Header() when the InfoLogLevel == HEADER_LEVEL. Updated tests in auto_roll_logger_test to ensure the header is handled properly in these cases. Test Plan: Augment existing tests in auto_roll_logger_test Reviewers: igor, sdong, yhchiang Reviewed By: yhchiang Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D41067
This commit is contained in:
parent
acee2b08a2
commit
35cd75c379
@ -615,6 +615,7 @@ enum InfoLogLevel : unsigned char {
|
||||
WARN_LEVEL,
|
||||
ERROR_LEVEL,
|
||||
FATAL_LEVEL,
|
||||
HEADER_LEVEL,
|
||||
NUM_INFO_LOG_LEVELS,
|
||||
};
|
||||
|
||||
|
@ -254,28 +254,29 @@ TEST_F(AutoRollLoggerTest, InfoLogLevel) {
|
||||
// becomes out of scope.
|
||||
{
|
||||
AutoRollLogger logger(Env::Default(), kTestDir, "", log_size, 0);
|
||||
for (int log_level = InfoLogLevel::FATAL_LEVEL;
|
||||
for (int log_level = InfoLogLevel::HEADER_LEVEL;
|
||||
log_level >= InfoLogLevel::DEBUG_LEVEL; log_level--) {
|
||||
logger.SetInfoLogLevel((InfoLogLevel)log_level);
|
||||
for (int log_type = InfoLogLevel::DEBUG_LEVEL;
|
||||
log_type <= InfoLogLevel::FATAL_LEVEL; log_type++) {
|
||||
log_type <= InfoLogLevel::HEADER_LEVEL; log_type++) {
|
||||
// log messages with log level smaller than log_level will not be
|
||||
// logged.
|
||||
LogMessage((InfoLogLevel)log_type, &logger, kSampleMessage.c_str());
|
||||
}
|
||||
log_lines += InfoLogLevel::FATAL_LEVEL - log_level + 1;
|
||||
log_lines += InfoLogLevel::HEADER_LEVEL - log_level + 1;
|
||||
}
|
||||
for (int log_level = InfoLogLevel::FATAL_LEVEL;
|
||||
for (int log_level = InfoLogLevel::HEADER_LEVEL;
|
||||
log_level >= InfoLogLevel::DEBUG_LEVEL; log_level--) {
|
||||
logger.SetInfoLogLevel((InfoLogLevel)log_level);
|
||||
|
||||
// again, messages with level smaller than log_level will not be logged.
|
||||
Log(InfoLogLevel::HEADER_LEVEL, &logger, "%s", kSampleMessage.c_str());
|
||||
Debug(&logger, "%s", kSampleMessage.c_str());
|
||||
Info(&logger, "%s", kSampleMessage.c_str());
|
||||
Warn(&logger, "%s", kSampleMessage.c_str());
|
||||
Error(&logger, "%s", kSampleMessage.c_str());
|
||||
Fatal(&logger, "%s", kSampleMessage.c_str());
|
||||
log_lines += InfoLogLevel::FATAL_LEVEL - log_level + 1;
|
||||
log_lines += InfoLogLevel::HEADER_LEVEL - log_level + 1;
|
||||
}
|
||||
}
|
||||
std::ifstream inFile(AutoRollLoggerTest::kLogFile.c_str());
|
||||
@ -329,19 +330,31 @@ TEST_F(AutoRollLoggerTest, LogHeaderTest) {
|
||||
static const size_t LOG_MAX_SIZE = 1024 * 5;
|
||||
static const std::string HEADER_STR = "Log header line";
|
||||
|
||||
// test_num == 0 -> standard call to Header()
|
||||
// test_num == 1 -> call to Log() with InfoLogLevel::HEADER_LEVEL
|
||||
for (int test_num = 0; test_num < 2; test_num++) {
|
||||
|
||||
InitTestDb();
|
||||
|
||||
AutoRollLogger logger(Env::Default(), kTestDir, /*db_log_dir=*/ "",
|
||||
LOG_MAX_SIZE, /*log_file_time_to_roll=*/ 0);
|
||||
|
||||
// log some headers
|
||||
if (test_num == 0) {
|
||||
// Log some headers explicitly using Header()
|
||||
for (size_t i = 0; i < MAX_HEADERS; i++) {
|
||||
Header(&logger, "%s %d", HEADER_STR.c_str(), i);
|
||||
}
|
||||
} else if (test_num == 1) {
|
||||
// HEADER_LEVEL should make this behave like calling Header()
|
||||
for (size_t i = 0; i < MAX_HEADERS; i++) {
|
||||
Log(InfoLogLevel::HEADER_LEVEL, &logger, "%s %d",
|
||||
HEADER_STR.c_str(), i);
|
||||
}
|
||||
}
|
||||
|
||||
const string& newfname = logger.TEST_log_fname().c_str();
|
||||
|
||||
// log enough data to cause a roll over
|
||||
// Log enough data to cause a roll over
|
||||
int i = 0;
|
||||
for (size_t iter = 0; iter < 2; iter++) {
|
||||
while (logger.GetLogFileSize() < LOG_MAX_SIZE) {
|
||||
@ -352,7 +365,7 @@ TEST_F(AutoRollLoggerTest, LogHeaderTest) {
|
||||
Info(&logger, "Rollover");
|
||||
}
|
||||
|
||||
// Flus the log for the latest file
|
||||
// Flush the log for the latest file
|
||||
LogFlush(&logger);
|
||||
|
||||
const list<string> oldfiles = GetOldFileNames(newfname);
|
||||
@ -366,6 +379,7 @@ TEST_F(AutoRollLoggerTest, LogHeaderTest) {
|
||||
ASSERT_EQ(GetLinesCount(oldfname, HEADER_STR), MAX_HEADERS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(AutoRollLoggerTest, LogFileExistence) {
|
||||
rocksdb::DB* db;
|
||||
|
@ -61,7 +61,13 @@ void Log(const InfoLogLevel log_level, Logger* info_log, const char* format,
|
||||
if (info_log && info_log->GetInfoLogLevel() <= log_level) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
||||
if (log_level == InfoLogLevel::HEADER_LEVEL) {
|
||||
info_log->LogHeader(format, ap);
|
||||
} else {
|
||||
info_log->Logv(log_level, format, ap);
|
||||
}
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user