diff --git a/conf/nebula-graphd.conf.default b/conf/nebula-graphd.conf.default index da2efa27c98..65d9d3604fb 100644 --- a/conf/nebula-graphd.conf.default +++ b/conf/nebula-graphd.conf.default @@ -28,7 +28,8 @@ --stderr_log_file=graphd-stderr.log # Copy log messages at or above this level to stderr in addition to logfiles. The numbers of severity levels INFO, WARNING, ERROR, and FATAL are 0, 1, 2, and 3, respectively. --stderrthreshold=2 - +# wether logging files' name contain time stamp. +--timestamp_in_logfile_name=true ########## query ########## # Whether to treat partial success as an error. # This flag is only used for Read-only access, and Modify access always treats partial success as an error. diff --git a/conf/nebula-graphd.conf.production b/conf/nebula-graphd.conf.production index 67798fa6942..0d178d03a56 100644 --- a/conf/nebula-graphd.conf.production +++ b/conf/nebula-graphd.conf.production @@ -26,6 +26,8 @@ --stderr_log_file=graphd-stderr.log # Copy log messages at or above this level to stderr in addition to logfiles. The numbers of severity levels INFO, WARNING, ERROR, and FATAL are 0, 1, 2, and 3, respectively. --stderrthreshold=2 +# wether logging files' name contain timestamp +--timestamp_in_logfile_name=true ########## query ########## # Whether to treat partial success as an error. diff --git a/conf/nebula-metad.conf.default b/conf/nebula-metad.conf.default index 332e31911c7..89e537b9a57 100644 --- a/conf/nebula-metad.conf.default +++ b/conf/nebula-metad.conf.default @@ -20,6 +20,8 @@ --stderr_log_file=metad-stderr.log # Copy log messages at or above this level to stderr in addition to logfiles. The numbers of severity levels INFO, WARNING, ERROR, and FATAL are 0, 1, 2, and 3, respectively. --stderrthreshold=2 +# wether logging files' name contain time stamp, If Using logrotate to rotate logging files, than should set it to true. +--timestamp_in_logfile_name=true ########## networking ########## # Comma separated Meta Server addresses diff --git a/conf/nebula-metad.conf.production b/conf/nebula-metad.conf.production index a7fb729315b..870ba6318c2 100644 --- a/conf/nebula-metad.conf.production +++ b/conf/nebula-metad.conf.production @@ -20,6 +20,8 @@ --stderr_log_file=metad-stderr.log # Copy log messages at or above this level to stderr in addition to logfiles. The numbers of severity levels INFO, WARNING, ERROR, and FATAL are 0, 1, 2, and 3, respectively. --stderrthreshold=2 +# wether logging files' name contain time stamp. +--timestamp_in_logfile_name=true ########## networking ########## # Comma separated Meta Server addresses diff --git a/conf/nebula-storaged-listener.conf.production b/conf/nebula-storaged-listener.conf.production index da6095117fb..6dff785502b 100644 --- a/conf/nebula-storaged-listener.conf.production +++ b/conf/nebula-storaged-listener.conf.production @@ -23,6 +23,8 @@ --stderr_log_file=storaged-stderr.log # Copy log messages at or above this level to stderr in addition to logfiles. The numbers of severity levels INFO, WARNING, ERROR, and FATAL are 0, 1, 2, and 3, respectively. --stderrthreshold=2 +# Wether logging files' name contain timestamp. +--timestamp_in_logfile_name=true ########## networking ########## # Meta server address diff --git a/conf/nebula-storaged.conf.default b/conf/nebula-storaged.conf.default index 59cd0f80cd9..b5e9019a52b 100644 --- a/conf/nebula-storaged.conf.default +++ b/conf/nebula-storaged.conf.default @@ -22,6 +22,8 @@ --stderr_log_file=storaged-stderr.log # Copy log messages at or above this level to stderr in addition to logfiles. The numbers of severity levels INFO, WARNING, ERROR, and FATAL are 0, 1, 2, and 3, respectively. --stderrthreshold=2 +# Wether logging files' name contain time stamp. +--timestamp_in_logfile_name=true ########## networking ########## # Comma separated Meta server addresses diff --git a/conf/nebula-storaged.conf.production b/conf/nebula-storaged.conf.production index 688fa36910e..18a71133731 100644 --- a/conf/nebula-storaged.conf.production +++ b/conf/nebula-storaged.conf.production @@ -22,6 +22,8 @@ --stderr_log_file=storaged-stderr.log # Copy log messages at or above this level to stderr in addition to logfiles. The numbers of severity levels INFO, WARNING, ERROR, and FATAL are 0, 1, 2, and 3, respectively. --stderrthreshold=2 +# Wether logging files' name contain timestamp. +--timestamp_in_logfile_name=true ########## networking ########## # Comma separated Meta server addresses diff --git a/src/daemons/GraphDaemon.cpp b/src/daemons/GraphDaemon.cpp index 87efa2107be..c5acae262e5 100644 --- a/src/daemons/GraphDaemon.cpp +++ b/src/daemons/GraphDaemon.cpp @@ -16,6 +16,7 @@ #include "common/process/ProcessUtils.h" #include "common/ssl/SSLConfig.h" #include "common/time/TimezoneInfo.h" +#include "daemons/SetupLogging.h" #include "graph/service/GraphFlags.h" #include "graph/service/GraphService.h" #include "graph/stats/GraphStats.h" @@ -33,7 +34,6 @@ static std::unique_ptr gServer; static void signalHandler(int sig); static Status setupSignalHandler(); -extern Status setupLogging(); static void printHelp(const char *prog); static void setupThreadManager(); #if defined(__x86_64__) @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) { } // Setup logging - auto status = setupLogging(); + auto status = setupLogging(argv[0]); if (!status.ok()) { LOG(ERROR) << status; return EXIT_FAILURE; diff --git a/src/daemons/MetaDaemon.cpp b/src/daemons/MetaDaemon.cpp index 11960bc7794..211a88d17d0 100644 --- a/src/daemons/MetaDaemon.cpp +++ b/src/daemons/MetaDaemon.cpp @@ -18,6 +18,7 @@ #include "common/thread/GenericThreadPool.h" #include "common/time/TimezoneInfo.h" #include "common/utils/MetaKeyUtils.h" +#include "daemons/SetupLogging.h" #include "kvstore/NebulaStore.h" #include "kvstore/PartManager.h" #include "meta/ActiveHostsMan.h" @@ -58,7 +59,6 @@ static std::unique_ptr gKVStore; static void signalHandler(int sig); static void waitForStop(); static Status setupSignalHandler(); -extern Status setupLogging(); #if defined(__x86_64__) extern Status setupBreakpad(); #endif @@ -71,7 +71,7 @@ int main(int argc, char* argv[]) { gflags::ParseCommandLineFlags(&argc, &argv, false); // Setup logging - auto status = setupLogging(); + auto status = setupLogging(argv[0]); if (!status.ok()) { LOG(ERROR) << status; return EXIT_FAILURE; diff --git a/src/daemons/SetupLogging.cpp b/src/daemons/SetupLogging.cpp index 2b34a07e440..18441d3be9e 100644 --- a/src/daemons/SetupLogging.cpp +++ b/src/daemons/SetupLogging.cpp @@ -3,10 +3,15 @@ * This source code is licensed under Apache 2.0 License. */ +#include "daemons/SetupLogging.h" + +#include + +#include + #include "common/base/Base.h" #include "common/base/Status.h" #include "common/fs/FileUtils.h" - DECLARE_string(log_dir); DEFINE_bool(redirect_stdout, true, "Whether to redirect stdout and stderr to separate files"); @@ -16,12 +21,17 @@ DEFINE_string(stderr_log_file, "stderr.log", "Destination filename of stderr"); using nebula::Status; using nebula::fs::FileUtils; -Status setupLogging() { +Status setupLogging(const std::string &exe) { // If the log directory does not exist, try to create - if (!FileUtils::exist(FLAGS_log_dir)) { - if (!FileUtils::makeDir(FLAGS_log_dir)) { - return Status::Error("Failed to create log directory `%s'", FLAGS_log_dir.c_str()); - } + if (!FileUtils::exist(FLAGS_log_dir) && !FileUtils::makeDir(FLAGS_log_dir)) { + return Status::Error("Failed to create log directory `%s'", FLAGS_log_dir.c_str()); + } + if (!FLAGS_timestamp_in_logfile_name) { + google::SetLogDestination(google::GLOG_INFO, (FLAGS_log_dir + '/' + exe + ".INFO").c_str()); + google::SetLogDestination(google::GLOG_WARNING, + (FLAGS_log_dir + '/' + exe + ".WARNING").c_str()); + google::SetLogDestination(google::GLOG_ERROR, (FLAGS_log_dir + '/' + exe + ".ERROR").c_str()); + google::SetLogDestination(google::GLOG_FATAL, (FLAGS_log_dir + '/' + exe + ".FATAL").c_str()); } if (!FLAGS_redirect_stdout) { diff --git a/src/daemons/SetupLogging.h b/src/daemons/SetupLogging.h new file mode 100644 index 00000000000..2f1764e924a --- /dev/null +++ b/src/daemons/SetupLogging.h @@ -0,0 +1,18 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#ifndef SETUPLOGGING_H +#define SETUPLOGGING_H + +#include + +#include "common/base/Status.h" +/** + * \param exe: program name. + * \return wether successfully setupLogging. + * + */ +nebula::Status setupLogging(const std::string &exe); +#endif diff --git a/src/daemons/StorageDaemon.cpp b/src/daemons/StorageDaemon.cpp index 0b7c6f0a104..e40625b531d 100644 --- a/src/daemons/StorageDaemon.cpp +++ b/src/daemons/StorageDaemon.cpp @@ -12,6 +12,7 @@ #include "common/network/NetworkUtils.h" #include "common/process/ProcessUtils.h" #include "common/time/TimezoneInfo.h" +#include "daemons/SetupLogging.h" #include "storage/StorageServer.h" #include "storage/stats/StorageStats.h" #include "version/Version.h" @@ -46,7 +47,6 @@ using nebula::network::NetworkUtils; static void signalHandler(int sig); static Status setupSignalHandler(); -extern Status setupLogging(); #if defined(__x86_64__) extern Status setupBreakpad(); #endif @@ -61,7 +61,7 @@ int main(int argc, char *argv[]) { gflags::ParseCommandLineFlags(&argc, &argv, false); // Setup logging - auto status = setupLogging(); + auto status = setupLogging(argv[0]); if (!status.ok()) { LOG(ERROR) << status; return EXIT_FAILURE;