diff --git a/conf/nebula-graphd.conf.default b/conf/nebula-graphd.conf.default index d57d3f8a28b..57c8fbdcaa7 100644 --- a/conf/nebula-graphd.conf.default +++ b/conf/nebula-graphd.conf.default @@ -30,6 +30,9 @@ --stderrthreshold=3 # wether logging files' name contain time stamp. --timestamp_in_logfile_name=true +# use max_log_size or log_clean_days to control the log file size and log file clean days. Set log_clean_days to 0 to disable log file cleaning. +--log_clean_days=0 + ########## 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-metad.conf.default b/conf/nebula-metad.conf.default index 89b594f36f5..e17e503ad2c 100644 --- a/conf/nebula-metad.conf.default +++ b/conf/nebula-metad.conf.default @@ -22,6 +22,8 @@ --stderrthreshold=3 # 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 +# use max_log_size or log_clean_days to control the log file size and log file clean days. Set log_clean_days to 0 to disable log file cleaning. +--log_clean_days=0 ########## networking ########## # Comma separated Meta Server addresses diff --git a/conf/nebula-standalone.conf.default b/conf/nebula-standalone.conf.default index e5f7a449efe..fc299a2c3bd 100644 --- a/conf/nebula-standalone.conf.default +++ b/conf/nebula-standalone.conf.default @@ -28,6 +28,8 @@ --stderr_log_file=standalone-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=3 +# use max_log_size or log_clean_days to control the log file size and log file clean days. Set log_clean_days to 0 to disable log file cleaning. +--log_clean_days=0 ########## query ########## # Whether to treat partial success as an error. diff --git a/conf/nebula-storaged-listener.conf.default b/conf/nebula-storaged-listener.conf.default index 86d74d3c356..35e39c53a94 100644 --- a/conf/nebula-storaged-listener.conf.default +++ b/conf/nebula-storaged-listener.conf.default @@ -25,6 +25,8 @@ --stderrthreshold=3 # Wether logging files' name contain timestamp. --timestamp_in_logfile_name=true +# use max_log_size or log_clean_days to control the log file size and log file clean days. Set log_clean_days to 0 to disable log file cleaning. +--log_clean_days=0 ########## networking ########## # Meta server address diff --git a/conf/nebula-storaged.conf.default b/conf/nebula-storaged.conf.default index 0d29f5547a6..a65422121da 100644 --- a/conf/nebula-storaged.conf.default +++ b/conf/nebula-storaged.conf.default @@ -24,6 +24,8 @@ --stderrthreshold=3 # Wether logging files' name contain time stamp. --timestamp_in_logfile_name=true +# use max_log_size or log_clean_days to control the log file size and log file clean days. Set log_clean_days to 0 to disable log file cleaning. +--log_clean_days=0 ########## networking ########## # Comma separated Meta server addresses diff --git a/src/daemons/SetupLogging.cpp b/src/daemons/SetupLogging.cpp index 3300ff48c10..8786f6f4fa1 100644 --- a/src/daemons/SetupLogging.cpp +++ b/src/daemons/SetupLogging.cpp @@ -18,6 +18,7 @@ DECLARE_string(log_dir); DEFINE_bool(redirect_stdout, true, "Whether to redirect stdout and stderr to separate files"); DEFINE_string(stdout_log_file, "stdout.log", "Destination filename of stdout"); DEFINE_string(stderr_log_file, "stderr.log", "Destination filename of stderr"); +DEFINE_int32(log_clean_days, 7, "clean log files older than the specified days"); using nebula::Status; using nebula::fs::FileUtils; @@ -43,6 +44,10 @@ Status setupLogging(const std::string &exe) { return Status::OK(); } + if (FLAGS_log_clean_days > 0) { + google::EnableLogCleaner(FLAGS_log_clean_days); + } + auto dup = [](const std::string &filename, FILE *stream) -> Status { auto path = FLAGS_log_dir + "/" + filename; auto fd = ::open(path.c_str(), O_WRONLY | O_APPEND | O_CREAT, 0644);