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

Allow to send logs to stdout/stderr #613

Merged
merged 2 commits into from
May 29, 2022
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
2 changes: 1 addition & 1 deletion cmake/glog.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ include(FetchContent)

FetchContent_Declare(glog
GIT_REPOSITORY https://github.com/google/glog
GIT_TAG v0.4.0
GIT_TAG v0.6.0
)

include(cmake/utils.cmake)
Expand Down
1 change: 1 addition & 0 deletions cmake/snappy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ include(cmake/utils.cmake)
FetchContent_MakeAvailableWithArgs(snappy
SNAPPY_BUILD_TESTS=OFF
SNAPPY_BUILD_BENCHMARKS=OFF
BUILD_SHARED_LIBS=OFF
)
9 changes: 5 additions & 4 deletions kvrocks.conf
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ db-name change.me.db
# Note that you must specify a directory here, not a file name.
dir /tmp/kvrocks

# The logs of server will be stored in this directory. If you don't specify
# one directory, by default, we store logs in the working directory that set
# by 'dir' above.
# log-dir /tmp/kvrocks
# You can configure where to store your server logs by the log-dir.
# If you don't specify one, we will use the above `dir` as our default log directory.
# We also can send logs to stdout/stderr is as simple as:
#
# log-dir stdout

# When running daemonized, kvrocks writes a pid file in ${CONFIG_DIR}/kvrocks.pid by
# default. You can specify a custom pid file location here.
Expand Down
11 changes: 10 additions & 1 deletion src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,16 @@ static void initGoogleLog(const Config *config) {
FLAGS_minloglevel = config->loglevel;
FLAGS_max_log_size = 100;
FLAGS_logbufsecs = 0;
FLAGS_log_dir = config->log_dir;

if (Util::ToLower(config->log_dir) == "stdout") {
for (int level = google::INFO; level <= google::FATAL; level++) {
google::SetLogDestination(level, "");
}
FLAGS_stderrthreshold = google::ERROR;
FLAGS_logtostdout = true;
} else {
FLAGS_log_dir = config->log_dir;
}
}

bool supervisedUpstart() {
Expand Down