Flag based logger functions

Moved initiation and termination of FRU VPD collection logging under
compile time flag. User can decide whether to log in a file or journal
while building the bmc image by setting/unsetting the particular flag.

Test:
Image loaded on a rainier system
- ls /var/lib/vpd/ - initially there was 1 collection log file
- Called CollectFRUVPD
- ls /var/lib/vpd/ - there were 2 collection log file
- Called CollectFRUVPD
- ls /var/lib/vpd/ - there were 3 collection log file
- Called CollectFRUVPD
- ls /var/lib/vpd/ - there were 3 collection log file, as max no is 3

Change-Id: I63238d63bea065f6b1c0fca6d66c87307a713f94
Signed-off-by: Alpana Kumari <alpu8007@gmail.com>
diff --git a/vpd-manager/include/logger.hpp b/vpd-manager/include/logger.hpp
index 1980b2b..ec63de7 100644
--- a/vpd-manager/include/logger.hpp
+++ b/vpd-manager/include/logger.hpp
@@ -308,16 +308,7 @@
                     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;
-
+#ifdef ENABLE_FILE_LOGGING
     /**
      * @brief API to terminate VPD collection logging.
      *
@@ -328,21 +319,40 @@
     {
         m_collectionLogger.reset();
     }
+#endif
 
   private:
     /**
      * @brief Constructor
      */
-    Logger() : m_vpdWriteLogger(nullptr), m_collectionLogger(nullptr) {}
+    Logger() : m_vpdWriteLogger(nullptr)
+    {
+#ifdef ENABLE_FILE_LOGGING
+        m_collectionLogger = nullptr;
+#endif
+    }
+
+#ifdef ENABLE_FILE_LOGGING
+    /**
+     * @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;
+
+    // logger object to handle VPD collection logs
+    std::unique_ptr<ILogFileHandler> m_collectionLogger;
+
+#endif
 
     // Instance to the logger class.
     static std::shared_ptr<Logger> m_loggerInstance;
 
     // 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 83042bb..d9e193a 100644
--- a/vpd-manager/oem-handler/ibm_handler.cpp
+++ b/vpd-manager/oem-handler/ibm_handler.cpp
@@ -157,9 +157,10 @@
                         "Correlated properties JSON path is not defined in system config JSON. Correlated properties listener is disabled.");
                 }
             }
-
+#ifdef ENABLE_FILE_LOGGING
             // terminate collection logger
             m_logger->terminateVpdCollectionLogging();
+#endif
         }
         else
         {
@@ -169,9 +170,10 @@
                 l_timer.cancel();
                 logging::logMessage("Taking too long. Active thread = " +
                                     std::to_string(l_threadCount));
-
+#ifdef ENABLE_FILE_LOGGING
                 // terminate collection logger
                 m_logger->terminateVpdCollectionLogging();
+#endif
             }
             else
             {
@@ -501,9 +503,6 @@
 
 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/src/logger.cpp b/vpd-manager/src/logger.cpp
index 504c3b2..8411aa2 100644
--- a/vpd-manager/src/logger.cpp
+++ b/vpd-manager/src/logger.cpp
@@ -16,11 +16,27 @@
     l_log << "FileName: " << i_location.file_name() << ","
           << " Line: " << i_location.line() << " " << i_message;
 
-    if ((i_placeHolder == PlaceHolder::COLLECTION) && m_collectionLogger)
+    if (i_placeHolder == PlaceHolder::COLLECTION)
     {
 #ifdef ENABLE_FILE_LOGGING
-        // Log it to a specific place.
-        m_collectionLogger->logMessage(l_log.str());
+        if (m_collectionLogger.get() == nullptr)
+        {
+            initiateVpdCollectionLogging();
+
+            if (m_collectionLogger.get() != nullptr)
+            {
+                // Log it to a specific place.
+                m_collectionLogger->logMessage(l_log.str());
+            }
+            else
+            {
+                std::cout << l_log.str() << std::endl;
+            }
+        }
+        else
+        {
+            m_collectionLogger->logMessage(l_log.str());
+        }
 #else
         std::cout << l_log.str() << std::endl;
 #endif
@@ -53,6 +69,7 @@
     }
 }
 
+#ifdef ENABLE_FILE_LOGGING
 void Logger::initiateVpdCollectionLogging() noexcept
 {
     try
@@ -144,6 +161,7 @@
                    std::string(l_ex.what()));
     }
 }
+#endif
 
 void SyncFileLogger::logMessage(const std::string_view& i_message)
 {