From 8fed4fb9a216707a3645b2ea6ce6114924aea83d Mon Sep 17 00:00:00 2001 From: git-hulk Date: Sun, 29 May 2022 12:10:34 +0800 Subject: [PATCH 1/2] Allow to send logs to stdout/stderr Currently, we only supported to send logs to the log file, but we epxected to collect logs through stdout/stderr instead of the log file when deploying the Kvrocks in the container. We also upgrade the glog to v0.6.0 since the logs to stdout was supported after that. --- cmake/glog.cmake | 2 +- kvrocks.conf | 9 +++++---- src/main.cc | 11 ++++++++++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/cmake/glog.cmake b/cmake/glog.cmake index a6ca92b217b..0552a86c9f2 100644 --- a/cmake/glog.cmake +++ b/cmake/glog.cmake @@ -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) diff --git a/kvrocks.conf b/kvrocks.conf index bfd000cd5ab..94fd4c183a4 100644 --- a/kvrocks.conf +++ b/kvrocks.conf @@ -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. diff --git a/src/main.cc b/src/main.cc index eb0adc59e5f..8972a2d6092 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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() { From 3ab662b36395e4df205d3d9baf31548056bc4f48 Mon Sep 17 00:00:00 2001 From: git-hulk Date: Sun, 29 May 2022 15:08:42 +0800 Subject: [PATCH 2/2] Disable BUILD_SHARED_LIBS in glog --- cmake/snappy.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/snappy.cmake b/cmake/snappy.cmake index 1bc5438702b..f9913e583a5 100644 --- a/cmake/snappy.cmake +++ b/cmake/snappy.cmake @@ -29,4 +29,5 @@ include(cmake/utils.cmake) FetchContent_MakeAvailableWithArgs(snappy SNAPPY_BUILD_TESTS=OFF SNAPPY_BUILD_BENCHMARKS=OFF + BUILD_SHARED_LIBS=OFF )