Pass info_log_level to the inner logger of AutoRollLogger (#6388)

Summary:
Before this fix, the info_log_level passed from CreateLoggerFromOptions() will
be ignored by AutoRollLogger::logger_. This PR fixes it by setting the info log
level of logger_ during ResetLogger().

Test plan (dev server):
```
COMPILE_WITH_TSAN=1 make all && make check
make all && make check
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6388

Differential Revision: D19828045

Pulled By: riversand963

fbshipit-source-id: e1ac7de3a2090bee53b6c667f71a11f1774163e6
main
Yanqin Jin 5 years ago committed by Facebook Github Bot
parent 35ed530d2c
commit 28aa09dcce
  1. 2
      logging/auto_roll_logger.cc
  2. 20
      logging/auto_roll_logger.h
  3. 22
      logging/auto_roll_logger_test.cc

@ -59,6 +59,8 @@ Status AutoRollLogger::ResetLogger() {
if (!status_.ok()) { if (!status_.ok()) {
return status_; return status_;
} }
assert(logger_);
logger_->SetInfoLogLevel(Logger::GetInfoLogLevel());
if (logger_->GetLogFileSize() == Logger::kDoNotSupportGetLogFileSize) { if (logger_->GetLogFileSize() == Logger::kDoNotSupportGetLogFileSize) {
status_ = Status::NotSupported( status_ = Status::NotSupported(

@ -73,6 +73,24 @@ class AutoRollLogger : public Logger {
} }
} }
using Logger::GetInfoLogLevel;
InfoLogLevel GetInfoLogLevel() const override {
MutexLock l(&mutex_);
if (!logger_) {
return Logger::GetInfoLogLevel();
}
return logger_->GetInfoLogLevel();
}
using Logger::SetInfoLogLevel;
void SetInfoLogLevel(const InfoLogLevel log_level) override {
MutexLock lock(&mutex_);
Logger::SetInfoLogLevel(log_level);
if (logger_) {
logger_->SetInfoLogLevel(log_level);
}
}
void SetCallNowMicrosEveryNRecords(uint64_t call_NowMicros_every_N_records) { void SetCallNowMicrosEveryNRecords(uint64_t call_NowMicros_every_N_records) {
call_NowMicros_every_N_records_ = call_NowMicros_every_N_records; call_NowMicros_every_N_records_ = call_NowMicros_every_N_records;
} }
@ -84,6 +102,8 @@ class AutoRollLogger : public Logger {
uint64_t TEST_ctime() const { return ctime_; } uint64_t TEST_ctime() const { return ctime_; }
Logger* TEST_inner_logger() const { return logger_.get(); }
protected: protected:
// Implementation of Close() // Implementation of Close()
virtual Status CloseImpl() override { virtual Status CloseImpl() override {

@ -132,6 +132,9 @@ void AutoRollLoggerTest::RollLogFileBySizeTest(AutoRollLogger* logger,
size_t log_max_size, size_t log_max_size,
const std::string& log_message) { const std::string& log_message) {
logger->SetInfoLogLevel(InfoLogLevel::INFO_LEVEL); logger->SetInfoLogLevel(InfoLogLevel::INFO_LEVEL);
ASSERT_EQ(InfoLogLevel::INFO_LEVEL, logger->GetInfoLogLevel());
ASSERT_EQ(InfoLogLevel::INFO_LEVEL,
logger->TEST_inner_logger()->GetInfoLogLevel());
// measure the size of each message, which is supposed // measure the size of each message, which is supposed
// to be equal or greater than log_message.size() // to be equal or greater than log_message.size()
LogMessage(logger, log_message.c_str()); LogMessage(logger, log_message.c_str());
@ -221,6 +224,25 @@ TEST_F(AutoRollLoggerTest, RollLogFileByTime) {
kSampleMessage + ":RollLogFileByTime"); kSampleMessage + ":RollLogFileByTime");
} }
TEST_F(AutoRollLoggerTest, SetInfoLogLevel) {
InitTestDb();
Options options;
options.info_log_level = InfoLogLevel::FATAL_LEVEL;
options.max_log_file_size = 1024;
std::shared_ptr<Logger> logger;
ASSERT_OK(CreateLoggerFromOptions(kTestDir, options, &logger));
auto* auto_roll_logger = dynamic_cast<AutoRollLogger*>(logger.get());
ASSERT_NE(nullptr, auto_roll_logger);
ASSERT_EQ(InfoLogLevel::FATAL_LEVEL, auto_roll_logger->GetInfoLogLevel());
ASSERT_EQ(InfoLogLevel::FATAL_LEVEL,
auto_roll_logger->TEST_inner_logger()->GetInfoLogLevel());
auto_roll_logger->SetInfoLogLevel(InfoLogLevel::DEBUG_LEVEL);
ASSERT_EQ(InfoLogLevel::DEBUG_LEVEL, auto_roll_logger->GetInfoLogLevel());
ASSERT_EQ(InfoLogLevel::DEBUG_LEVEL, logger->GetInfoLogLevel());
ASSERT_EQ(InfoLogLevel::DEBUG_LEVEL,
auto_roll_logger->TEST_inner_logger()->GetInfoLogLevel());
}
TEST_F(AutoRollLoggerTest, OpenLogFilesMultipleTimesWithOptionLog_max_size) { TEST_F(AutoRollLoggerTest, OpenLogFilesMultipleTimesWithOptionLog_max_size) {
// If only 'log_max_size' options is specified, then every time // If only 'log_max_size' options is specified, then every time
// when rocksdb is restarted, a new empty log file will be created. // when rocksdb is restarted, a new empty log file will be created.

Loading…
Cancel
Save