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
This commit is contained in:
parent
8ca30bd51b
commit
4405f3a000
@ -513,7 +513,7 @@ class Directory {
|
||||
virtual Status Fsync() = 0;
|
||||
};
|
||||
|
||||
enum InfoLogLevel {
|
||||
enum InfoLogLevel : unsigned char {
|
||||
DEBUG = 0,
|
||||
INFO,
|
||||
WARN,
|
||||
@ -526,7 +526,7 @@ enum InfoLogLevel {
|
||||
class Logger {
|
||||
public:
|
||||
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) {}
|
||||
virtual ~Logger();
|
||||
|
||||
@ -543,10 +543,20 @@ class Logger {
|
||||
if (log_level < log_level_) {
|
||||
return;
|
||||
}
|
||||
char new_format[500];
|
||||
snprintf(new_format, sizeof(new_format) - 1, "[%s] %s",
|
||||
kInfoLogLevelNames[log_level], format);
|
||||
Logv(new_format, ap);
|
||||
|
||||
if (log_level == INFO) {
|
||||
// Doesn't print log level if it is INFO level.
|
||||
// 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 {
|
||||
return DO_NOT_SUPPORT_GET_LOG_FILE_SIZE;
|
||||
|
@ -24,6 +24,7 @@ class CompactionFilter;
|
||||
class CompactionFilterFactory;
|
||||
class Comparator;
|
||||
class Env;
|
||||
enum InfoLogLevel : unsigned char;
|
||||
class FilterPolicy;
|
||||
class Logger;
|
||||
class MergeOperator;
|
||||
@ -152,6 +153,8 @@ struct Options {
|
||||
// Default: nullptr
|
||||
shared_ptr<Logger> info_log;
|
||||
|
||||
InfoLogLevel info_log_level;
|
||||
|
||||
// -------------------
|
||||
// Parameters that affect performance
|
||||
|
||||
|
@ -88,7 +88,7 @@ Status CreateLoggerFromOptions(
|
||||
AutoRollLogger* result = new AutoRollLogger(
|
||||
env, dbname, db_log_dir,
|
||||
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();
|
||||
if (!s.ok()) {
|
||||
delete result;
|
||||
@ -101,7 +101,11 @@ Status CreateLoggerFromOptions(
|
||||
env->CreateDir(dbname); // In case it does not exist
|
||||
env->RenameFile(fname, OldInfoLogFileName(dbname, env->NowMicros(),
|
||||
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,
|
||||
const std::string& db_log_dir, size_t log_max_size,
|
||||
size_t log_file_time_to_roll,
|
||||
const InfoLogLevel log_level = InfoLogLevel::ERROR)
|
||||
const InfoLogLevel log_level = InfoLogLevel::INFO)
|
||||
: Logger(log_level),
|
||||
dbname_(dbname),
|
||||
db_log_dir_(db_log_dir),
|
||||
|
@ -40,7 +40,7 @@ void Log(Logger* info_log, const char* format, ...) {
|
||||
if (info_log) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
info_log->Logv(format, ap);
|
||||
info_log->Logv(InfoLogLevel::INFO, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
@ -163,7 +163,7 @@ void Log(const shared_ptr<Logger>& info_log, const char* format, ...) {
|
||||
if (info_log) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
info_log->Logv(format, ap);
|
||||
info_log->Logv(InfoLogLevel::INFO, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ Options::Options()
|
||||
paranoid_checks(false),
|
||||
env(Env::Default()),
|
||||
info_log(nullptr),
|
||||
info_log_level(INFO),
|
||||
write_buffer_size(4<<20),
|
||||
max_write_buffer_number(2),
|
||||
min_write_buffer_number_to_merge(1),
|
||||
|
Loading…
Reference in New Issue
Block a user