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

feat: add config for log cleaner #1171

Merged
merged 9 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions kvrocks.conf
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ dir /tmp/kvrocks
# We also can send logs to stdout/stderr is as simple as:
#
log-dir stdout
# log-dir log

# To enable the log cleaner. if set yes , glog will check if there are
# overdue logs whenever a flush is performed
enablelogcleaner yes

# INFO level log file whose last modified time is greater than logcleanerday
# will be unlinked
logcleanerday 0

# When running in daemonize mode, kvrocks writes a PID file in ${CONFIG_DIR}/kvrocks.pid by
# default. You can specify a custom pid file location here.
Expand Down
2 changes: 2 additions & 0 deletions src/config/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ Config::Config() {
{"migrate-sequence-gap", false, new IntField(&sequence_gap, 10000, 1, INT_MAX)},
{"unixsocket", true, new StringField(&unixsocket, "")},
{"unixsocketperm", true, new OctalField(&unixsocketperm, 0777, 1, INT_MAX)},
{"enablelogcleaner", false, new YesNoField(&enablelogcleaner, false)},
{"logcleanerday", false, new IntField(&logcleanerday, 365, 0, INT_MAX)},

/* rocksdb options */
{"rocksdb.compression", false, new EnumField(&RocksDB.compression, compression_type_enum, 0)},
Expand Down
2 changes: 2 additions & 0 deletions src/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ struct Config {
int pipeline_size;
int sequence_gap;

bool enablelogcleaner;
int logcleanerday;
// profiling
int profiling_sample_ratio = 0;
int profiling_sample_record_threshold_ms = 0;
Expand Down
9 changes: 9 additions & 0 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ static void initGoogleLog(const Config *config) {
FLAGS_logtostdout = true;
} else {
FLAGS_log_dir = config->log_dir;
if (config->enablelogcleaner) {
google::EnableLogCleaner(config->logcleanerday);
google::SetLogFilenameExtension(".log");
for (int level = google::INFO; level <= google::FATAL; level++) {
std::string des = google::LogSeverityNames[level];
des = config->log_dir + "/kvrocks_" + des + "_";
google::SetLogDestination(level, des.c_str());
}
}
}
}

Expand Down