Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to set log level via config file #1230

Merged
merged 2 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions kvrocks.conf
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ dir /tmp/kvrocks
#
log-dir stdout

# Log level
# Possible values: info, warning, error, fatal
# Default: info
log-level info

# You can configure log-retention-days to control whether to enable the log cleaner
# and the maximum retention days that the INFO level logs will be kept.
#
Expand Down
24 changes: 16 additions & 8 deletions src/config/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,22 @@ const char *errBlobDbNotEnabled = "Must set rocksdb.enable_blob_files to yes fir
const char *errLevelCompactionDynamicLevelBytesNotSet =
"Must set rocksdb.level_compaction_dynamic_level_bytes yes first.";

configEnum compression_type_enum[] = {
configEnum compression_types[] = {
{"no", rocksdb::CompressionType::kNoCompression}, {"snappy", rocksdb::CompressionType::kSnappyCompression},
{"lz4", rocksdb::CompressionType::kLZ4Compression}, {"zstd", rocksdb::CompressionType::kZSTD},
{"zlib", rocksdb::CompressionType::kZlibCompression}, {nullptr, 0}};

configEnum supervised_mode_enum[] = {{"no", kSupervisedNone},
{"auto", kSupervisedAutoDetect},
{"upstart", kSupervisedUpStart},
{"systemd", kSupervisedSystemd},
{nullptr, 0}};
configEnum supervised_modes[] = {{"no", kSupervisedNone},
{"auto", kSupervisedAutoDetect},
{"upstart", kSupervisedUpStart},
{"systemd", kSupervisedSystemd},
{nullptr, 0}};

configEnum log_levels[] = {{"info", google::INFO},
{"warning", google::WARNING},
{"error", google::ERROR},
{"fatal", google::FATAL},
{nullptr, 0}};

std::string trimRocksDBPrefix(std::string s) {
if (strncasecmp(s.data(), "rocksdb.", 8) != 0) return s;
Expand Down Expand Up @@ -124,12 +130,13 @@ Config::Config() {
{"dir", true, new StringField(&dir, "/tmp/kvrocks")},
{"backup-dir", false, new StringField(&backup_dir, "")},
{"log-dir", true, new StringField(&log_dir, "")},
{"log-level", true, new EnumField(&log_level, log_levels, google::INFO)},
{"pidfile", true, new StringField(&pidfile, "")},
{"max-io-mb", false, new IntField(&max_io_mb, 500, 0, INT_MAX)},
{"max-bitmap-to-string-mb", false, new IntField(&max_bitmap_to_string_mb, 16, 0, INT_MAX)},
{"max-db-size", false, new IntField(&max_db_size, 0, 0, INT_MAX)},
{"max-replication-mb", false, new IntField(&max_replication_mb, 0, 0, INT_MAX)},
{"supervised", true, new EnumField(&supervised_mode, supervised_mode_enum, kSupervisedNone)},
{"supervised", true, new EnumField(&supervised_mode, supervised_modes, kSupervisedNone)},
{"slave-serve-stale-data", false, new YesNoField(&slave_serve_stale_data, true)},
{"slave-empty-db-before-fullsync", false, new YesNoField(&slave_empty_db_before_fullsync, false)},
{"slave-priority", false, new IntField(&slave_priority, 100, 0, INT_MAX)},
Expand All @@ -155,7 +162,8 @@ Config::Config() {
{"log-retention-days", false, new IntField(&log_retention_days, -1, -1, INT_MAX)},

/* rocksdb options */
{"rocksdb.compression", false, new EnumField(&RocksDB.compression, compression_type_enum, 0)},
{"rocksdb.compression", false,
new EnumField(&RocksDB.compression, compression_types, rocksdb::CompressionType::kNoCompression)},
{"rocksdb.block_size", true, new IntField(&RocksDB.block_size, 4096, 0, INT_MAX)},
{"rocksdb.max_open_files", false, new IntField(&RocksDB.max_open_files, 4096, -1, INT_MAX)},
{"rocksdb.write_buffer_size", false, new IntField(&RocksDB.write_buffer_size, 64, 0, 4096)},
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct Config {
int tls_session_cache_timeout = 300;
int workers = 0;
int timeout = 0;
int loglevel = 0;
int log_level = 0;
int backlog = 511;
int maxclients = 10000;
int max_backup_to_keep = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ static CLIOptions parseCommandLineOptions(int argc, char **argv) {
}

static void initGoogleLog(const Config *config) {
FLAGS_minloglevel = config->loglevel;
FLAGS_minloglevel = config->log_level;
FLAGS_max_log_size = 100;
FLAGS_logbufsecs = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/storage/scripting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ int redisLogCommand(lua_State *lua) {
lua_pushstring(lua, "Invalid debug level.");
return lua_error(lua);
}
if (level < GetServer()->GetConfig()->loglevel) {
if (level < GetServer()->GetConfig()->log_level) {
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion utils/kvrocks2redis/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Status Config::parseConfigFromString(const std::string &input) {
}
pidfile = output_dir + "kvrocks2redis.pid";
next_seq_file_path = output_dir + "last_next_seq.txt";
} else if (size == 1 && key == "loglevel") {
} else if (size == 1 && key == "log-level") {
for (size_t i = 0; i < kNumLogLevel; i++) {
if (Util::ToLower(args[0]) == kLogLevels[i]) {
loglevel = static_cast<int>(i);
Expand Down
2 changes: 1 addition & 1 deletion utils/kvrocks2redis/kvrocks2redis.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# The value should be INFO, WARNING, ERROR, FATAL.
#
# Default: INFO
loglevel INFO
log-level INFO

# By default kvrocks2redis does not run as a daemon. Use 'yes' if you need it.
# Note that kvrocks2redis will write a pid file in /var/run/kvrocks2redis.pid when daemonized.
Expand Down