Skip to content

Commit

Permalink
Support change log-level in runtime (#1611)
Browse files Browse the repository at this point in the history
Now we support config set log-level xxx to modify log-level
in runtime.

This closes #1610.
  • Loading branch information
enjoy-binbin authored Jul 26, 2023
1 parent 0e28dac commit 509220c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/config/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ 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)},
{"log-level", false, 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)},
Expand Down Expand Up @@ -478,6 +478,12 @@ void Config::initFieldCallback() {
if (cluster_enabled) srv->slot_migrator->SetSequenceGapLimit(sequence_gap);
return Status::OK();
}},
{"log-level",
[this](Server *srv, const std::string &k, const std::string &v) -> Status {
if (!srv) return Status::OK();
FLAGS_minloglevel = log_level;
return Status::OK();
}},
{"log-retention-days",
[this](Server *srv, const std::string &k, const std::string &v) -> Status {
if (!srv) return Status::OK();
Expand Down
1 change: 1 addition & 0 deletions tests/cppunit/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ TEST(Config, GetAndSet) {
auto s = config.Load(CLIOptions(path));
EXPECT_FALSE(s.IsOK());
std::map<std::string, std::string> mutable_cases = {
{"log-level", "info"},
{"timeout", "1000"},
{"maxclients", "2000"},
{"max-backup-to-keep", "1"},
Expand Down

0 comments on commit 509220c

Please sign in to comment.