Skip to content

Commit

Permalink
fix(util): stop write log to stderr, when FLAGS_logtostderr is false
Browse files Browse the repository at this point in the history
close: opencurve#2811

Signed-off-by: NaturalSelect <2145973003@qq.com>
  • Loading branch information
NaturalSelect committed Nov 10, 2023
1 parent ba61d87 commit 81b2bd0
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions curvefs/src/client/curve_fuse_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions curvefs/src/mds/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <glog/logging.h>

#include "curvefs/src/mds/mds.h"
#include "src/common/log_util.h"
#include "src/common/configuration.h"
#include "curvefs/src/common/dynamic_vlog.h"

Expand Down Expand Up @@ -64,6 +65,7 @@ int main(int argc, char **argv) {
}

// initialize logging module
curve::common::DisableLoggingToStdErr();
google::InitGoogleLogging(argv[0]);

conf->PrintConfig();
Expand Down
2 changes: 2 additions & 0 deletions curvefs/src/metaserver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions nebd/src/part2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
#include <unistd.h>
#include <glog/logging.h>
#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();

Expand Down
2 changes: 2 additions & 0 deletions src/chunkserver/chunkserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -105,6 +106,7 @@ int ChunkServer::Run(int argc, char** argv) {
LoadConfigFromCmdline(&conf);

// 初始化日志模块
curve::common::DisableLoggingToStdErr();
google::InitGoogleLogging(argv[0]);

// 打印参数
Expand Down
31 changes: 31 additions & 0 deletions src/common/log_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.
*/

#ifndef SRC_COMMON_LOG_UTIL_H_
#define SRC_COMMON_LOG_UTIL_H_

#include <glog/logging.h>

namespace curve {
namespace common {
inline void DisableLoggingToStdErr() {
// NOTE: https://github.com/google/glog#setting-flags
FLAGS_stderrthreshold = 3;
}
} // namespace common
} // namespace curve

#endif // SRC_COMMON_LOG_UTIL_H_
1 change: 1 addition & 0 deletions src/mds/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ int main(int argc, char **argv) {
}

// initialize logging module
curve::common::DisableLoggingToStdErr();
google::InitGoogleLogging(argv[0]);

// reset SIGPIPE handler
Expand Down
2 changes: 2 additions & 0 deletions src/snapshotcloneserver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <glog/logging.h>
#include <gflags/gflags.h>
#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");
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 81b2bd0

Please sign in to comment.