Logger changes for VPD collection and write logs
This commit includes changes in Logger class for handling VPD collection
and VPD write logs. VPD collection and VPD write logs need to be handled
by different LogFileHandler instances. This commit also adds public
methods to initiate and terminate VPD collection logging. These methods
are required to control start and stop of VPD collection logs.
Change-Id: Idcc2da3d600819c8e88543a5d45161b9642634ad
Signed-off-by: Souvik Roy <souvikroyofficial10@gmail.com>
diff --git a/vpd-manager/include/logger.hpp b/vpd-manager/include/logger.hpp
index bedc688..575aa19 100644
--- a/vpd-manager/include/logger.hpp
+++ b/vpd-manager/include/logger.hpp
@@ -18,9 +18,10 @@
*/
enum class PlaceHolder
{
- DEFAULT, /* logs to the journal */
- PEL, /* Creates a PEL */
- COLLECTION /* Logs collection messages */
+ DEFAULT, /* logs to the journal */
+ PEL, /* Creates a PEL */
+ COLLECTION, /* Logs collection messages */
+ VPD_WRITE /* Logs VPD write details */
};
/**
@@ -28,7 +29,7 @@
* Based on the placeholder the class will handle different file operations to
* log error messages.
*/
-class LogFileHandler
+class ILogFileHandler
{
// should hold fd's for files required as per placeholder.
public:
@@ -54,7 +55,7 @@
* @brief Constructor
* Private so that can't be initialized by class(es) other than friends.
*/
- LogFileHandler() {}
+ ILogFileHandler() {}
/* Define APIs to handle file operation as per the placeholder. */
};
@@ -68,8 +69,10 @@
/**
* @brief Deleted Methods
*/
- Logger(const Logger&) = delete; // Copy constructor
- Logger(const Logger&&) = delete; // Move constructor
+ Logger(const Logger&) = delete; // Copy constructor
+ Logger(const Logger&&) = delete; // Move constructor
+ Logger operator=(const Logger&) = delete; // Copy assignment operator
+ Logger operator=(const Logger&&) = delete; // Move assignment operator
/**
* @brief Method to get instance of Logger class.
@@ -99,21 +102,44 @@
const std::source_location& i_location =
std::source_location::current());
+ /**
+ * @brief API to initiate VPD collection logging.
+ *
+ * This API initiates VPD collection logging. It checks for existing
+ * collection log files and if 3 such files are found, it deletes the oldest
+ * file and initiates a VPD collection logger object, so that every new VPD
+ * collection flow always gets logged into a new file.
+ */
+ void initiateVpdCollectionLogging() noexcept;
+
+ /**
+ * @brief API to terminate VPD collection logging.
+ *
+ * This API terminates the VPD collection logging by destroying the
+ * associated VPD collection logger object.
+ */
+ void terminateVpdCollectionLogging() noexcept
+ {
+ // TODO: reset VPD collection logger
+ }
+
private:
/**
* @brief Constructor
*/
- Logger() : m_logFileHandler(nullptr)
+ Logger() : m_vpdWriteLogger(nullptr), m_collectionLogger(nullptr)
{
- m_logFileHandler =
- std::shared_ptr<LogFileHandler>(new LogFileHandler());
+ // TODO: initiate synchronous logger for VPD write logs
}
// Instance to the logger class.
static std::shared_ptr<Logger> m_loggerInstance;
- // Instance to LogFileHandler class.
- std::shared_ptr<LogFileHandler> m_logFileHandler;
+ // logger object to handle VPD write logs
+ std::unique_ptr<ILogFileHandler> m_vpdWriteLogger;
+
+ // logger object to handle VPD collection logs
+ std::unique_ptr<ILogFileHandler> m_collectionLogger;
};
/**
diff --git a/vpd-manager/oem-handler/ibm_handler.cpp b/vpd-manager/oem-handler/ibm_handler.cpp
index 436c617..df25af9 100644
--- a/vpd-manager/oem-handler/ibm_handler.cpp
+++ b/vpd-manager/oem-handler/ibm_handler.cpp
@@ -21,7 +21,8 @@
const std::shared_ptr<sdbusplus::asio::connection>& i_asioConnection) :
m_worker(o_worker), m_backupAndRestoreObj(o_backupAndRestoreObj),
m_interface(i_iFace), m_progressInterface(i_progressiFace),
- m_ioContext(i_ioCon), m_asioConnection(i_asioConnection)
+ m_ioContext(i_ioCon), m_asioConnection(i_asioConnection),
+ m_logger(Logger::getLoggerInstance())
{
if (dbusUtility::isChassisPowerOn())
{
@@ -127,6 +128,9 @@
{
m_eventListener->registerCorrPropCallBack();
}
+
+ // terminate collection logger
+ m_logger->terminateVpdCollectionLogging();
}
else
{
@@ -136,6 +140,9 @@
l_timer.cancel();
logging::logMessage("Taking too long. Active thread = " +
std::to_string(l_threadCount));
+
+ // terminate collection logger
+ m_logger->terminateVpdCollectionLogging();
}
else
{
@@ -500,6 +507,9 @@
void IbmHandler::collectAllFruVpd()
{
+ // initialize VPD collection logger
+ m_logger->initiateVpdCollectionLogging();
+
// Setting status to "InProgress", before trigeering VPD collection.
m_progressInterface->set_property(
"Status", std::string(constants::vpdCollectionInProgress));
diff --git a/vpd-manager/oem-handler/ibm_handler.hpp b/vpd-manager/oem-handler/ibm_handler.hpp
index 1eb9d3f..bead9e1 100644
--- a/vpd-manager/oem-handler/ibm_handler.hpp
+++ b/vpd-manager/oem-handler/ibm_handler.hpp
@@ -3,6 +3,7 @@
#include "backup_restore.hpp"
#include "gpio_monitor.hpp"
#include "listener.hpp"
+#include "logger.hpp"
#include "worker.hpp"
#include <sdbusplus/asio/object_server.hpp>
@@ -166,5 +167,8 @@
// Shared pointer to Listener object.
std::shared_ptr<Listener> m_eventListener;
+
+ // Shared pointer to Logger object.
+ std::shared_ptr<Logger> m_logger;
};
} // namespace vpd
diff --git a/vpd-manager/src/logger.cpp b/vpd-manager/src/logger.cpp
index 62d4e9e..0c189bf 100644
--- a/vpd-manager/src/logger.cpp
+++ b/vpd-manager/src/logger.cpp
@@ -15,10 +15,10 @@
l_log << "FileName: " << i_location.file_name() << ","
<< " Line: " << i_location.line() << " " << i_message;
- if (i_placeHolder == PlaceHolder::COLLECTION)
+ if ((i_placeHolder == PlaceHolder::COLLECTION) && m_collectionLogger)
{
// Log it to a specific place.
- m_logFileHandler->writeLogToFile(i_placeHolder);
+ m_collectionLogger->writeLogToFile(i_placeHolder);
}
else if (i_placeHolder == PlaceHolder::PEL)
{
@@ -32,6 +32,10 @@
l_log.str() + ">"
<< std::endl;
}
+ else if ((i_placeHolder == PlaceHolder::VPD_WRITE) && m_vpdWriteLogger)
+ {
+ m_vpdWriteLogger->writeLogToFile(i_placeHolder);
+ }
else
{
// Default case, let it go to journal.
@@ -39,6 +43,27 @@
}
}
+void Logger::initiateVpdCollectionLogging() noexcept
+{
+ try
+ {
+ /* TODO:
+ - check /var/lib/vpd for number "collection.*" log file
+ - if 3 collection_[0-2].log files are found
+ - delete collection_1.log
+ - create collection logger object with collection_1.log
+ parameter
+ - else
+ - create collection logger object with collection_(n+1).log
+ parameter*/
+ }
+ catch (const std::exception& l_ex)
+ {
+ logMessage("Failed to initialize collection logger. Error: " +
+ std::string(l_ex.what()));
+ }
+}
+
namespace logging
{
void logMessage(std::string_view message, const std::source_location& location)