Base framework for log management
The commit implements stub of logger class and log file handler class,
which together will be further extended to implement methods required
for abstracting log management from the caller and will log message at
appropriate place.
Change-Id: Ieb53ec5d0377fbad062f1150bcbf24c335a7ce80
Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
diff --git a/vpd-manager/src/logger.cpp b/vpd-manager/src/logger.cpp
index 19959a1..62d4e9e 100644
--- a/vpd-manager/src/logger.cpp
+++ b/vpd-manager/src/logger.cpp
@@ -4,6 +4,41 @@
namespace vpd
{
+std::shared_ptr<Logger> Logger::m_loggerInstance;
+
+void Logger::logMessage(std::string_view i_message,
+ const PlaceHolder& i_placeHolder,
+ const types::PelInfoTuple* i_pelTuple,
+ const std::source_location& i_location)
+{
+ std::ostringstream l_log;
+ l_log << "FileName: " << i_location.file_name() << ","
+ << " Line: " << i_location.line() << " " << i_message;
+
+ if (i_placeHolder == PlaceHolder::COLLECTION)
+ {
+ // Log it to a specific place.
+ m_logFileHandler->writeLogToFile(i_placeHolder);
+ }
+ else if (i_placeHolder == PlaceHolder::PEL)
+ {
+ if (i_pelTuple)
+ {
+ // LOG PEL
+ // This should call create PEL API from the event logger.
+ return;
+ }
+ std::cout << "Pel info tuple required to log PEL for message <" +
+ l_log.str() + ">"
+ << std::endl;
+ }
+ else
+ {
+ // Default case, let it go to journal.
+ std::cout << l_log.str() << std::endl;
+ }
+}
+
namespace logging
{
void logMessage(std::string_view message, const std::source_location& location)
@@ -12,11 +47,6 @@
log << "FileName: " << location.file_name() << ","
<< " Line: " << location.line() << " " << message;
- /* TODO: Check on this later.
- log << "FileName: " << location.file_name() << ","
- << " Line: " << location.line() << ","
- << " Func: " << location.function_name() << ", " << message;*/
-
std::cout << log.str() << std::endl;
}
} // namespace logging