From e209909d9d855a20f0405fbc1d6ca12ffa7079b9 Mon Sep 17 00:00:00 2001 From: atarekra Date: Mon, 26 Jan 2026 15:17:08 +0200 Subject: [PATCH] Adding changes related to logfile size feature --- .../file_recorder/file_recorder_factory.cpp | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/score/mw/log/detail/file_recorder/file_recorder_factory.cpp b/score/mw/log/detail/file_recorder/file_recorder_factory.cpp index 75331c0..136764d 100644 --- a/score/mw/log/detail/file_recorder/file_recorder_factory.cpp +++ b/score/mw/log/detail/file_recorder/file_recorder_factory.cpp @@ -38,13 +38,25 @@ std::unique_ptr FileRecorderFactory::CreateFileLoggingBackend( const Configuration& config, score::cpp::pmr::memory_resource* memory_resource) noexcept { - const std::string file_name{std::string(config.GetLogFilePath().data(), config.GetLogFilePath().size()) + "/" + - std::string{config.GetAppId().data(), config.GetAppId().size()} + ".dlt"}; + const std::string file_path_base{std::string(config.GetLogFilePath().data(), config.GetLogFilePath().size())}; + const std::string app_id{std::string{config.GetAppId().data(), config.GetAppId().size()}}; + const std::string file_extension{".dlt"}; + std::string file_name{file_path_base + "/" + app_id + file_extension}; + if (config.GetNoOfLogFiles() > 1) { + file_name = file_path_base + "/" + app_id + "_1" + file_extension; + } + + auto open_flags = score::os::Fcntl::Open::kReadWrite | score::os::Fcntl::Open::kCreate | score::os::Fcntl::Open::kCloseOnExec; + if (!config.IsCircularFileLogging()) + { + open_flags |= score::os::Fcntl::Open::kAppend; + } + // NOLINTBEGIN(score-banned-function): FileLoggingBackend is disabled in production. Argumentation: Ticket-75726 const auto descriptor_result = fcntl_->open( file_name.data(), - score::os::Fcntl::Open::kWriteOnly | score::os::Fcntl::Open::kCreate | score::os::Fcntl::Open::kCloseOnExec, + open_flags, score::os::Stat::Mode::kReadUser | score::os::Stat::Mode::kWriteUser | score::os::Stat::Mode::kReadGroup | score::os::Stat::Mode::kReadOthers); // NOLINTEND(score-banned-function): see above for detailed explanation @@ -72,9 +84,15 @@ std::unique_ptr FileRecorderFactory::CreateFileLoggingBackend( return std::make_unique(std::move(message_builder), descriptor, + file_name, std::move(allocator), score::os::Fcntl::Default(memory_resource), - score::os::Unistd::Default(memory_resource)); + score::os::Unistd::Default(memory_resource), + config.IsCircularFileLogging(), + config.IsOverwriteLogOnFull(), + config.GetMaxLogFileSizeBytes(), + config.GetNoOfLogFiles(), + config.IsTruncateOnRotation()); } } // namespace detail