Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logrotate #3541

Merged
merged 21 commits into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion conf/nebula-graphd.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions conf/nebula-graphd.conf.production
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions conf/nebula-metad.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo whether

--timestamp_in_logfile_name=true

########## networking ##########
# Comma separated Meta Server addresses
Expand Down
2 changes: 2 additions & 0 deletions conf/nebula-metad.conf.production
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions conf/nebula-storaged-listener.conf.production
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions conf/nebula-storaged.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions conf/nebula-storaged.conf.production
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/daemons/GraphDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -33,7 +34,6 @@ static std::unique_ptr<apache::thrift::ThriftServer> 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__)
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/daemons/MetaDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -58,7 +59,6 @@ static std::unique_ptr<nebula::kvstore::KVStore> gKVStore;
static void signalHandler(int sig);
static void waitForStop();
static Status setupSignalHandler();
extern Status setupLogging();
#if defined(__x86_64__)
extern Status setupBreakpad();
#endif
Expand All @@ -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;
Expand Down
22 changes: 16 additions & 6 deletions src/daemons/SetupLogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
* This source code is licensed under Apache 2.0 License.
*/

#include "daemons/SetupLogging.h"

#include <glog/logging.h>

#include <string>

#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");
Expand All @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions src/daemons/SetupLogging.h
Original file line number Diff line number Diff line change
@@ -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 <string>

#include "common/base/Status.h"
/**
* \param exe: program name.
* \return wether successfully setupLogging.
*
*/
nebula::Status setupLogging(const std::string &exe);
#endif
4 changes: 2 additions & 2 deletions src/daemons/StorageDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down