FileLogger:async file logging stub
This commit implements a class to handle asynchronous file logging. It
extends the LogFileHandler class. Logging messages to file from multiple
VPD collection threads synchronously affects the overall VPD collection
time, hence these logs need to be handled asynchronously. This commit
includes stub changes only and actual implementation will be handled in
future commit(s).
Change-Id: I81342e20a10015364d7de5b77531688aeabe6000
Signed-off-by: Souvik Roy <souvikroyofficial10@gmail.com>
diff --git a/vpd-manager/src/logger.cpp b/vpd-manager/src/logger.cpp
index 254a177..f7acfb4 100644
--- a/vpd-manager/src/logger.cpp
+++ b/vpd-manager/src/logger.cpp
@@ -56,6 +56,8 @@
- else
- create collection logger object with collection_(n+1).log
parameter*/
+ m_collectionLogger.reset(
+ new AsyncFileLogger("/var/lib/vpd/collection.log", 512));
}
catch (const std::exception& l_ex)
{
@@ -82,6 +84,35 @@
}
}
+void AsyncFileLogger::logMessage(
+ [[maybe_unused]] const std::string_view& i_message)
+{
+ try
+ {
+ /* TODO:
+ - acquire lock on queue
+ - push message to queue
+ - notify log worker thread
+ */
+ }
+ catch (const std::exception& l_ex)
+ {
+ auto l_logger = Logger::getLoggerInstance();
+ l_logger->logMessage(i_message);
+ }
+}
+
+void AsyncFileLogger::fileWorker() noexcept
+{
+ /* TODO:
+ - start an infinite loop
+ - check exit conditions and exit if needed
+ - wait for notification from log producer
+ - if notification received, flush the messages from queue to file
+ - rotate file if needed
+ */
+}
+
void ILogFileHandler::rotateFile(
[[maybe_unused]] const unsigned i_numEntriesToDelete)
{