From d5aff2c3011b485b0de6513179119b799b994d20 Mon Sep 17 00:00:00 2001 From: NaturalSelect <2145973003@qq.com> Date: Thu, 9 Nov 2023 10:02:15 +0800 Subject: [PATCH] fix(util): stop write log to stderr, when FLAGS_logtostderr is false close: #2811 Signed-off-by: NaturalSelect <2145973003@qq.com> --- curvefs/src/client/curve_fuse_op.cpp | 2 ++ curvefs/src/mds/main.cpp | 2 ++ curvefs/src/metaserver/main.cpp | 2 ++ nebd/src/part2/main.cpp | 2 ++ src/chunkserver/chunkserver.cpp | 2 ++ src/common/log_util.h | 25 +++++++++++++++++++++++++ src/mds/main/main.cpp | 1 + src/snapshotcloneserver/main.cpp | 2 ++ 8 files changed, 38 insertions(+) create mode 100644 src/common/log_util.h diff --git a/curvefs/src/client/curve_fuse_op.cpp b/curvefs/src/client/curve_fuse_op.cpp index dd249c8892..cd2128d805 100644 --- a/curvefs/src/client/curve_fuse_op.cpp +++ b/curvefs/src/client/curve_fuse_op.cpp @@ -48,6 +48,7 @@ #include "curvefs/src/common/metric_utils.h" #include "src/common/configuration.h" #include "src/common/gflags_helper.h" +#include "src/common/log_util.h" using ::curve::common::Configuration; using ::curvefs::client::CURVEFS_ERROR; @@ -152,6 +153,7 @@ int InitLog(const char *confPath, const char *argv0) { FLAGS_vlog_level = FLAGS_v; // initialize logging module + curve::common::DisableLoggingToStdErr(); google::InitGoogleLogging(argv0); bool succ = InitAccessLog(FLAGS_log_dir); diff --git a/curvefs/src/mds/main.cpp b/curvefs/src/mds/main.cpp index 725c29e89c..f506b4e5c8 100644 --- a/curvefs/src/mds/main.cpp +++ b/curvefs/src/mds/main.cpp @@ -24,6 +24,7 @@ #include #include "curvefs/src/mds/mds.h" +#include "src/common/log_util.h" #include "src/common/configuration.h" #include "curvefs/src/common/dynamic_vlog.h" @@ -64,6 +65,7 @@ int main(int argc, char **argv) { } // initialize logging module + curve::common::DisableLoggingToStdErr(); google::InitGoogleLogging(argv[0]); conf->PrintConfig(); diff --git a/curvefs/src/metaserver/main.cpp b/curvefs/src/metaserver/main.cpp index ec390ab951..5552dd5bed 100644 --- a/curvefs/src/metaserver/main.cpp +++ b/curvefs/src/metaserver/main.cpp @@ -29,6 +29,7 @@ #include "src/common/configuration.h" #include "curvefs/src/common/dynamic_vlog.h" #include "curvefs/src/common/threading.h" +#include "src/common/log_util.h" DEFINE_string(confPath, "curvefs/conf/metaserver.conf", "metaserver confPath"); DEFINE_string(ip, "127.0.0.1", "metasetver listen ip"); @@ -126,6 +127,7 @@ int main(int argc, char **argv) { FLAGS_vlog_level = FLAGS_v; // initialize logging module + curve::common::DisableLoggingToStdErr(); google::InitGoogleLogging(argv[0]); conf->PrintConfig(); diff --git a/nebd/src/part2/main.cpp b/nebd/src/part2/main.cpp index f8c742fe9a..e72bb27cbf 100644 --- a/nebd/src/part2/main.cpp +++ b/nebd/src/part2/main.cpp @@ -24,12 +24,14 @@ #include #include #include "nebd/src/part2/nebd_server.h" +#include "src/common/log_util.h" DEFINE_string(confPath, "/etc/nebd/nebd-server.conf", "nebd server conf path"); int main(int argc, char* argv[]) { // 解析参数 google::ParseCommandLineFlags(&argc, &argv, false); + curve::common::DisableLoggingToStdErr(); google::InitGoogleLogging(argv[0]); std::string confPath = FLAGS_confPath.c_str(); diff --git a/src/chunkserver/chunkserver.cpp b/src/chunkserver/chunkserver.cpp index bf5e711fa9..22f302c9da 100644 --- a/src/chunkserver/chunkserver.cpp +++ b/src/chunkserver/chunkserver.cpp @@ -45,6 +45,7 @@ #include "src/common/concurrent/task_thread_pool.h" #include "src/common/curve_version.h" #include "src/common/uri_parser.h" +#include "src/common/log_util.h" using ::curve::fs::LocalFileSystem; using ::curve::fs::LocalFileSystemOption; @@ -105,6 +106,7 @@ int ChunkServer::Run(int argc, char** argv) { LoadConfigFromCmdline(&conf); // 初始化日志模块 + curve::common::DisableLoggingToStdErr(); google::InitGoogleLogging(argv[0]); // 打印参数 diff --git a/src/common/log_util.h b/src/common/log_util.h new file mode 100644 index 0000000000..48a09b5b23 --- /dev/null +++ b/src/common/log_util.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 NetEase Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace curve { +namespace common { + inline void DisableLoggingToStdErr() { + // NOTE: https://github.com/google/glog#setting-flags + FLAGS_stderrthreshold = 3; + } +}} \ No newline at end of file diff --git a/src/mds/main/main.cpp b/src/mds/main/main.cpp index c0824f3bca..7e32e3055f 100644 --- a/src/mds/main/main.cpp +++ b/src/mds/main/main.cpp @@ -107,6 +107,7 @@ int main(int argc, char **argv) { } // initialize logging module + curve::common::DisableLoggingToStdErr(); google::InitGoogleLogging(argv[0]); // reset SIGPIPE handler diff --git a/src/snapshotcloneserver/main.cpp b/src/snapshotcloneserver/main.cpp index b44468b857..3430ff0118 100644 --- a/src/snapshotcloneserver/main.cpp +++ b/src/snapshotcloneserver/main.cpp @@ -22,6 +22,7 @@ #include #include #include "src/snapshotcloneserver/snapshotclone_server.h" +#include "src/common/log_util.h" DEFINE_string(conf, "conf/snapshot_clone_server.conf", "snapshot&clone server config file path"); //NOLINT DEFINE_string(addr, "127.0.0.1:5555", "snapshotcloneserver address"); @@ -80,6 +81,7 @@ int main(int argc, char **argv) { LoadConfigFromCmdline(conf.get()); conf->PrintConfig(); conf->ExposeMetric("snapshot_clone_server_config"); + curve::common::DisableLoggingToStdErr(); google::InitGoogleLogging(argv[0]); snapshotcloneserver_main(conf); }