mirror of
https://github.com/darlinghq/darlingserver.git
synced 2024-11-26 22:00:26 +00:00
[log] Add mode argument and check for success
Make sure to pass a file mode argument to `open` (this is required with `O_CREAT`. Also, make sure to check for success (i.e. non-negative FD) before trying to using the log file.
This commit is contained in:
parent
ce156a461f
commit
a88ba44119
@ -24,6 +24,7 @@
|
||||
#include <filesystem>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define DEFAULT_LOG_CUTOFF DarlingServer::Log::Type::Error
|
||||
|
||||
@ -103,7 +104,7 @@ void DarlingServer::Log::_log(Type type, std::string message) const {
|
||||
static int logFile = []() {
|
||||
std::filesystem::path path(Server::sharedInstance().prefix() + "/private/var/log/dserver.log");
|
||||
std::filesystem::create_directories(path.parent_path());
|
||||
return open(path.c_str(), O_WRONLY | O_APPEND | O_CREAT);
|
||||
return open(path.c_str(), O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||
}();
|
||||
|
||||
static bool logToStderr = []() {
|
||||
@ -128,7 +129,7 @@ void DarlingServer::Log::_log(Type type, std::string message) const {
|
||||
return level;
|
||||
}();
|
||||
|
||||
if (type < logMinLevel && !_alwaysLog) {
|
||||
if ((type < logMinLevel && !_alwaysLog) || logFile < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user