fgerlits commented on a change in pull request #1259:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1259#discussion_r806679388



##########
File path: libminifi/src/core/logging/LoggerConfiguration.cpp
##########
@@ -359,6 +323,57 @@ void LoggerConfiguration::initializeCompression(const 
std::lock_guard<std::mutex
   }
 }
 
+std::shared_ptr<spdlog::sinks::rotating_file_sink_mt> 
LoggerConfiguration::getRotatingFileSink(const std::string& appender_key, const 
std::shared_ptr<LoggerProperties>& properties) {
+  static std::map<std::filesystem::path, 
std::shared_ptr<spdlog::sinks::rotating_file_sink_mt>> rotating_file_sinks;
+  static std::mutex sink_map_mtx;
+
+  std::string file_name;
+  if (!properties->getString(appender_key + ".file_name", file_name)) {
+    file_name = "minifi-app.log";
+  }
+  std::string directory;
+  if (!properties->getString(appender_key + ".directory", directory)) {
+    // The below part assumes logger_properties->getHome() is existing
+    // Cause minifiHome must be set at MiNiFiMain.cpp?
+    directory = properties->getHome() + 
utils::file::FileUtils::get_separator() + "logs";
+  }
+
+  file_name = directory + utils::file::FileUtils::get_separator() + file_name;
+  if (utils::file::FileUtils::create_dir(directory) == -1) {
+    std::cerr << directory << " cannot be created\n";
+    exit(1);
+  }
+
+  int max_files = 3;
+  std::string max_files_str = "";
+  if (properties->getString(appender_key + ".max_files", max_files_str)) {
+    try {
+      max_files = std::stoi(max_files_str);
+    } catch (const std::invalid_argument &) {
+    } catch (const std::out_of_range &) {
+    }
+  }
+
+  int max_file_size = 5_MiB;
+  std::string max_file_size_str = "";
+  if (properties->getString(appender_key + ".max_file_size", 
max_file_size_str)) {
+    try {
+      max_file_size = std::stoi(max_file_size_str);
+    } catch (const std::invalid_argument &) {
+    } catch (const std::out_of_range &) {
+    }
+  }
+
+  std::lock_guard<std::mutex> guard(sink_map_mtx);
+  auto it = rotating_file_sinks.find(file_name);
+  if (it != rotating_file_sinks.end()) {
+    return it->second;
+  }

Review comment:
       Thanks, makes sense.  But I don't think the new comment is clear; 
something like
   ```
   // According to spdlog docs, if two loggers write to the same file, they 
must use the same sink object.
   // Note that some logging configuration changes will not take effect until 
MiNiFi is restarted.
   ```
   would be better.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to