Allow user to specify log level for info_log

Summary:
Currently, there is no easy way for user to change log level of info log. Add a parameter in options to specify that.
Also make the default level to INFO level. Removing the [INFO] tag if it is INFO level as I don't want to cause performance regression. (add [LOG] means another mem-copy and string formatting).

Test Plan:
make all check
manual check the levels work as expected.

Reviewers: dhruba, yhchiang

Reviewed By: yhchiang

CC: dhruba, igor, i.am.jin.lei, ljin, haobo, leveldb

Differential Revision: https://reviews.facebook.net/D16563
main
sdong 11 years ago
parent 8ca30bd51b
commit 4405f3a000
  1. 22
      include/rocksdb/env.h
  2. 3
      include/rocksdb/options.h
  3. 8
      util/auto_roll_logger.cc
  4. 2
      util/auto_roll_logger.h
  5. 4
      util/env.cc
  6. 1
      util/options.cc

@ -513,7 +513,7 @@ class Directory {
virtual Status Fsync() = 0; virtual Status Fsync() = 0;
}; };
enum InfoLogLevel { enum InfoLogLevel : unsigned char {
DEBUG = 0, DEBUG = 0,
INFO, INFO,
WARN, WARN,
@ -526,7 +526,7 @@ enum InfoLogLevel {
class Logger { class Logger {
public: public:
enum { DO_NOT_SUPPORT_GET_LOG_FILE_SIZE = -1 }; enum { DO_NOT_SUPPORT_GET_LOG_FILE_SIZE = -1 };
explicit Logger(const InfoLogLevel log_level = InfoLogLevel::ERROR) explicit Logger(const InfoLogLevel log_level = InfoLogLevel::INFO)
: log_level_(log_level) {} : log_level_(log_level) {}
virtual ~Logger(); virtual ~Logger();
@ -543,10 +543,20 @@ class Logger {
if (log_level < log_level_) { if (log_level < log_level_) {
return; return;
} }
char new_format[500];
snprintf(new_format, sizeof(new_format) - 1, "[%s] %s", if (log_level == INFO) {
kInfoLogLevelNames[log_level], format); // Doesn't print log level if it is INFO level.
Logv(new_format, ap); // This is to avoid unexpected performance regression after we add
// the feature of log level. All the logs before we add the feature
// are INFO level. We don't want to add extra costs to those existing
// logging.
Logv(format, ap);
} else {
char new_format[500];
snprintf(new_format, sizeof(new_format) - 1, "[%s] %s",
kInfoLogLevelNames[log_level], format);
Logv(new_format, ap);
}
} }
virtual size_t GetLogFileSize() const { virtual size_t GetLogFileSize() const {
return DO_NOT_SUPPORT_GET_LOG_FILE_SIZE; return DO_NOT_SUPPORT_GET_LOG_FILE_SIZE;

@ -24,6 +24,7 @@ class CompactionFilter;
class CompactionFilterFactory; class CompactionFilterFactory;
class Comparator; class Comparator;
class Env; class Env;
enum InfoLogLevel : unsigned char;
class FilterPolicy; class FilterPolicy;
class Logger; class Logger;
class MergeOperator; class MergeOperator;
@ -152,6 +153,8 @@ struct Options {
// Default: nullptr // Default: nullptr
shared_ptr<Logger> info_log; shared_ptr<Logger> info_log;
InfoLogLevel info_log_level;
// ------------------- // -------------------
// Parameters that affect performance // Parameters that affect performance

@ -88,7 +88,7 @@ Status CreateLoggerFromOptions(
AutoRollLogger* result = new AutoRollLogger( AutoRollLogger* result = new AutoRollLogger(
env, dbname, db_log_dir, env, dbname, db_log_dir,
options.max_log_file_size, options.max_log_file_size,
options.log_file_time_to_roll); options.log_file_time_to_roll, options.info_log_level);
Status s = result->GetStatus(); Status s = result->GetStatus();
if (!s.ok()) { if (!s.ok()) {
delete result; delete result;
@ -101,7 +101,11 @@ Status CreateLoggerFromOptions(
env->CreateDir(dbname); // In case it does not exist env->CreateDir(dbname); // In case it does not exist
env->RenameFile(fname, OldInfoLogFileName(dbname, env->NowMicros(), env->RenameFile(fname, OldInfoLogFileName(dbname, env->NowMicros(),
db_absolute_path, db_log_dir)); db_absolute_path, db_log_dir));
return env->NewLogger(fname, logger); auto s = env->NewLogger(fname, logger);
if (logger->get() != nullptr) {
(*logger)->SetInfoLogLevel(options.info_log_level);
}
return s;
} }
} }

@ -19,7 +19,7 @@ class AutoRollLogger : public Logger {
AutoRollLogger(Env* env, const std::string& dbname, AutoRollLogger(Env* env, const std::string& dbname,
const std::string& db_log_dir, size_t log_max_size, const std::string& db_log_dir, size_t log_max_size,
size_t log_file_time_to_roll, size_t log_file_time_to_roll,
const InfoLogLevel log_level = InfoLogLevel::ERROR) const InfoLogLevel log_level = InfoLogLevel::INFO)
: Logger(log_level), : Logger(log_level),
dbname_(dbname), dbname_(dbname),
db_log_dir_(db_log_dir), db_log_dir_(db_log_dir),

@ -40,7 +40,7 @@ void Log(Logger* info_log, const char* format, ...) {
if (info_log) { if (info_log) {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
info_log->Logv(format, ap); info_log->Logv(InfoLogLevel::INFO, format, ap);
va_end(ap); va_end(ap);
} }
} }
@ -163,7 +163,7 @@ void Log(const shared_ptr<Logger>& info_log, const char* format, ...) {
if (info_log) { if (info_log) {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
info_log->Logv(format, ap); info_log->Logv(InfoLogLevel::INFO, format, ap);
va_end(ap); va_end(ap);
} }
} }

@ -38,6 +38,7 @@ Options::Options()
paranoid_checks(false), paranoid_checks(false),
env(Env::Default()), env(Env::Default()),
info_log(nullptr), info_log(nullptr),
info_log_level(INFO),
write_buffer_size(4<<20), write_buffer_size(4<<20),
max_write_buffer_number(2), max_write_buffer_number(2),
min_write_buffer_number_to_merge(1), min_write_buffer_number_to_merge(1),

Loading…
Cancel
Save