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
Signed-off-by: NaturalSelect <[email protected]>
  • Loading branch information
NaturalSelect committed Nov 7, 2023
1 parent 09d2f02 commit d8b97d4
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions src/common/log_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,12 @@

#include <gflags/gflags.h>
#include <glog/logging.h>
#include <sys/stat.h>
#include <fcntl.h>

static int DisableStderr() {
// NOTE: use "/dev/stderr" to reopen stderr fd
int fd = ::open("/dev/null",O_APPEND|O_WRONLY);
if (fd == -1) {
return -1;
}
int r = ::dup2(fd,::fileno(stderr));
if (r == -1) {
return r;
}
::close(fd);
return 0;
}

void curve::common::InitGoogleLogging(const char *argv0) {
if (!FLAGS_logtostderr && !FLAGS_alsologtostderr) {
DisableStderr();
// NOTE: FLAGS_stderrthreshold don't controlled by FLAGS_logtostderr
// glog stil write log to stderr even if FLAGS_logtostderr is false.
FLAGS_stderrthreshold = 3;
}
google::InitGoogleLogging(argv0);
}

0 comments on commit d8b97d4

Please sign in to comment.