Implement padded log entry based log rotation
This commit implements log file rotation. If the number of entries in a
log file crosses a specified threshold, the write position is wrapped to
the beginning of the file so that the size of the file and subsequently
the size of BMC dump doesn't keep increasing infinitely. Each log entry
is padded or trimmed to ensure they are of fixed size.
Change-Id: I61bf0431adef9482180bf3463a96f7e0d6aea023
Signed-off-by: Souvik Roy <souvikroyofficial10@gmail.com>
diff --git a/vpd-manager/include/logger.hpp b/vpd-manager/include/logger.hpp
index 9d3283e..8dc8b55 100644
--- a/vpd-manager/include/logger.hpp
+++ b/vpd-manager/include/logger.hpp
@@ -49,18 +49,24 @@
// current number of log entries in file
size_t m_currentNumEntries{0};
+ // number of chars in a single log entry
+ size_t m_logEntrySize{512};
+
/**
* @brief API to rotate file.
*
- * This API rotates the logs within a file by deleting specified number of
- * oldest entries.
+ * This API rotates the logs within a file by repositioning the write file
+ * pointer to beginning of file. Rotation is achieved by overwriting the
+ * oldest log entries starting from the top of the file.
*
- * @param[in] i_numEntriesToDelete - Number of entries to delete.
- *
- * @throw std::runtime_error
+ * @throw std::ios_base::failure
*/
- virtual void rotateFile(
- [[maybe_unused]] const unsigned i_numEntriesToDelete = 5);
+ virtual inline void rotateFile()
+ {
+ // reset file pointer to beginning of file
+ m_fileStream.seekp(0);
+ m_currentNumEntries = 0;
+ }
/**
* @brief Constructor.