diff --git a/bpf_generic/src/log.cpp b/bpf_generic/src/log.cpp index b3980e6..6856605 100644 --- a/bpf_generic/src/log.cpp +++ b/bpf_generic/src/log.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include @@ -11,22 +11,23 @@ namespace logging { constexpr std::size_t max_size = 10 * 1024 * 1024; constexpr std::size_t max_files = 3; -void setUpLogger(const std::string& logDir, bool logToStdout) { - namespace fs = std::filesystem; +namespace fs = std::filesystem; +void setUpLogger(const fs::path logDir, bool logToStdout) { std::vector sinks; + if (logToStdout){ sinks.emplace_back(std::make_shared()); } if (!logDir.empty()) { - fs::path logPath; - if (!fs::is_directory(logDir)) { - spdlog::warn("{} doesn't exist or is not a directory.", logDir); - } - else { - std::string logFile = fmt::format("{}/oneagent_nettracer_{:d}.log", logDir, getpid()); - sinks.emplace_back(std::make_shared(logFile, max_size, max_files)); + std::error_code ec; + bool dirExists = fs::exists(logDir, ec); + if (!dirExists || ec || !fs::is_directory(logDir)) { + exit(5); + } else { + auto logFile = logDir / fmt::format("oneagent_nettracer_{:d}.log", getpid()); + sinks.emplace_back(std::make_shared(logFile.string(), max_size, max_files)); } } diff --git a/bpf_generic/src/log.h b/bpf_generic/src/log.h index 8e7e26f..ea2cb52 100644 --- a/bpf_generic/src/log.h +++ b/bpf_generic/src/log.h @@ -2,6 +2,7 @@ #define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG #include +#include #include #include @@ -13,7 +14,7 @@ inline std::shared_ptr getLogger() { return spdlog::get(LOGGER_NAME); } -void setUpLogger(const std::string& logDir, bool logToStdout); +void setUpLogger(const std::filesystem::path logDir, bool logToStdout); } // namespace logging diff --git a/nettracersrv/unified_log.cpp b/nettracersrv/unified_log.cpp index 64b7386..8f3ba13 100644 --- a/nettracersrv/unified_log.cpp +++ b/nettracersrv/unified_log.cpp @@ -8,9 +8,6 @@ bool setUpLogging(const boost::program_options::variables_map& vm) { bool noStdoutLog = vm.count("no_stdout_log"); bool noFileLog = logger_path.empty(); - if (!noFileLog) { - std::filesystem::create_directory(logger_path); - } logging::setUpLogger(logger_path, !noStdoutLog); if (areDebugLogsEnabled(vm)) { logging::getLogger()->set_level(spdlog::level::debug); diff --git a/version.properties b/version.properties index 46d5266..4d3251e 100644 --- a/version.properties +++ b/version.properties @@ -1 +1 @@ -version=1.1.9 +version=1.1.10