+// Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include "common/history_logger.h"
+
+#include <memory>
+#include <string>
+
+#include "common/utils/file_logbackend.h"
+#include "common/utils/request.h"
+
+namespace {
+
+constexpr const char kHistoryFileName[] = LOGDIR"/installation-history.log";
+constexpr const int kLogRotationSize = 1024 * 256; // 256KB
+constexpr const int kLogMaximumRotation = 3;
+
+} // namespace
+
+namespace common_installer {
+
+HistoryLogger::HistoryLogger() : started_(false) {
+ backend_ = std::make_unique<utils::FileLogBackend>(kHistoryFileName,
+ kLogRotationSize, kLogMaximumRotation);
+}
+
+void HistoryLogger::LogHistoryStart(const std::string& pkgid,
+ RequestType type) {
+ if (started_)
+ return;
+
+ HistoryBuilder builder;
+ builder.Append(pkgid).Append(GetRequestTypeString(type)).Append("START");
+ backend_->WriteLog(::utils::LogLevel::LOG_INFO, "", builder.Build());
+ backend_->WriteLogToFile();
+
+ started_ = true;
+}
+
+void HistoryLogger::LogHistoryEnd(const std::string& pkgid,
+ RequestType type, bool success) {
+ HistoryBuilder builder;
+ builder.Append(pkgid).Append(GetRequestTypeString(type));
+ if (success)
+ builder.Append("SUCCESS");
+ else
+ builder.Append("FAIL");
+ backend_->WriteLog(::utils::LogLevel::LOG_INFO, "", builder.Build());
+ backend_->WriteLogToFile();
+}
+
+} // namespace common_installer