diff --git a/conf/nebula-graphd.conf.default b/conf/nebula-graphd.conf.default index 441f714cf..36864a2ce 100644 --- a/conf/nebula-graphd.conf.default +++ b/conf/nebula-graphd.conf.default @@ -7,7 +7,7 @@ --enable_optimizer=true ########## logging ########## -# The directory to host logging files, which must already exists +# The directory to host logging files --log_dir=logs # Log level, 0, 1, 2, 3 for INFO, WARNING, ERROR, FATAL respectively --minloglevel=0 diff --git a/conf/nebula-graphd.conf.production b/conf/nebula-graphd.conf.production index 89c3f78a2..dccec9356 100644 --- a/conf/nebula-graphd.conf.production +++ b/conf/nebula-graphd.conf.production @@ -7,7 +7,7 @@ --enable_optimizer=true ########## logging ########## -# The directory to host logging files, which must already exists +# The directory to host logging files --log_dir=logs # Log level, 0, 1, 2, 3 for INFO, WARNING, ERROR, FATAL respectively --minloglevel=0 diff --git a/src/daemons/GraphDaemon.cpp b/src/daemons/GraphDaemon.cpp index c17880cca..024a7ccf4 100644 --- a/src/daemons/GraphDaemon.cpp +++ b/src/daemons/GraphDaemon.cpp @@ -25,6 +25,7 @@ using nebula::Status; using nebula::ProcessUtils; using nebula::graph::GraphService; using nebula::network::NetworkUtils; +using nebula::fs::FileUtils; static std::unique_ptr gServer; @@ -197,6 +198,14 @@ void signalHandler(int sig) { Status setupLogging() { + // 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 (!FLAGS_redirect_stdout) { return Status::OK(); }