Move hostlogger utilities
clang-tidy misc-include-fixer tries to remove the log_services.hpp
include from systems_logsevices_hostlogger.hpp file. This causes these
two helper functions to go missing.
These arguably should've been moved in
7945eeed0fe8f9c7bf07669294499ae0108da1d3 where we created this file, but
the second best time to plant a tree is now, so move them.
Tested: Code compiles. No test harnesses for hostlogger.
Change-Id: Ic0693472deb6c3bd355f042a0105661fa0873dfe
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 4b6d7af..665e058 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -8,7 +8,6 @@
#include "error_messages.hpp"
#include "generated/enums/log_entry.hpp"
#include "generated/enums/log_service.hpp"
-#include "gzfile.hpp"
#include "http_utility.hpp"
#include "human_sort.hpp"
#include "query.hpp"
@@ -1920,66 +1919,6 @@
});
}
-constexpr const char* hostLoggerFolderPath = "/var/log/console";
-
-inline bool
- getHostLoggerFiles(const std::string& hostLoggerFilePath,
- std::vector<std::filesystem::path>& hostLoggerFiles)
-{
- std::error_code ec;
- std::filesystem::directory_iterator logPath(hostLoggerFilePath, ec);
- if (ec)
- {
- BMCWEB_LOG_WARNING("{}", ec.message());
- return false;
- }
- for (const std::filesystem::directory_entry& it : logPath)
- {
- std::string filename = it.path().filename();
- // Prefix of each log files is "log". Find the file and save the
- // path
- if (filename.starts_with("log"))
- {
- hostLoggerFiles.emplace_back(it.path());
- }
- }
- // As the log files rotate, they are appended with a ".#" that is higher for
- // the older logs. Since we start from oldest logs, sort the name in
- // descending order.
- std::sort(hostLoggerFiles.rbegin(), hostLoggerFiles.rend(),
- AlphanumLess<std::string>());
-
- return true;
-}
-
-inline bool getHostLoggerEntries(
- const std::vector<std::filesystem::path>& hostLoggerFiles, uint64_t skip,
- uint64_t top, std::vector<std::string>& logEntries, size_t& logCount)
-{
- GzFileReader logFile;
-
- // Go though all log files and expose host logs.
- for (const std::filesystem::path& it : hostLoggerFiles)
- {
- if (!logFile.gzGetLines(it.string(), skip, top, logEntries, logCount))
- {
- BMCWEB_LOG_ERROR("fail to expose host logs");
- return false;
- }
- }
- // Get lastMessage from constructor by getter
- std::string lastMessage = logFile.getLastMessage();
- if (!lastMessage.empty())
- {
- logCount++;
- if (logCount > skip && logCount <= (skip + top))
- {
- logEntries.push_back(lastMessage);
- }
- }
- return true;
-}
-
inline void handleBMCLogServicesCollectionGet(
crow::App& app, const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
diff --git a/redfish-core/lib/systems_logservices_hostlogger.hpp b/redfish-core/lib/systems_logservices_hostlogger.hpp
index adcac33..7e9a7b7 100644
--- a/redfish-core/lib/systems_logservices_hostlogger.hpp
+++ b/redfish-core/lib/systems_logservices_hostlogger.hpp
@@ -4,6 +4,8 @@
#include "app.hpp"
#include "generated/enums/log_entry.hpp"
+#include "gzfile.hpp"
+#include "human_sort.hpp""
#include "query.hpp"
#include "registries/openbmc_message_registry.hpp"
#include "registries/privilege_registry.hpp"
@@ -17,6 +19,65 @@
namespace redfish
{
+constexpr const char* hostLoggerFolderPath = "/var/log/console";
+
+inline bool
+ getHostLoggerFiles(const std::string& hostLoggerFilePath,
+ std::vector<std::filesystem::path>& hostLoggerFiles)
+{
+ std::error_code ec;
+ std::filesystem::directory_iterator logPath(hostLoggerFilePath, ec);
+ if (ec)
+ {
+ BMCWEB_LOG_WARNING("{}", ec.message());
+ return false;
+ }
+ for (const std::filesystem::directory_entry& it : logPath)
+ {
+ std::string filename = it.path().filename();
+ // Prefix of each log files is "log". Find the file and save the
+ // path
+ if (filename.starts_with("log"))
+ {
+ hostLoggerFiles.emplace_back(it.path());
+ }
+ }
+ // As the log files rotate, they are appended with a ".#" that is higher for
+ // the older logs. Since we start from oldest logs, sort the name in
+ // descending order.
+ std::sort(hostLoggerFiles.rbegin(), hostLoggerFiles.rend(),
+ AlphanumLess<std::string>());
+
+ return true;
+}
+
+inline bool getHostLoggerEntries(
+ const std::vector<std::filesystem::path>& hostLoggerFiles, uint64_t skip,
+ uint64_t top, std::vector<std::string>& logEntries, size_t& logCount)
+{
+ GzFileReader logFile;
+
+ // Go though all log files and expose host logs.
+ for (const std::filesystem::path& it : hostLoggerFiles)
+ {
+ if (!logFile.gzGetLines(it.string(), skip, top, logEntries, logCount))
+ {
+ BMCWEB_LOG_ERROR("fail to expose host logs");
+ return false;
+ }
+ }
+ // Get lastMessage from constructor by getter
+ std::string lastMessage = logFile.getLastMessage();
+ if (!lastMessage.empty())
+ {
+ logCount++;
+ if (logCount > skip && logCount <= (skip + top))
+ {
+ logEntries.push_back(lastMessage);
+ }
+ }
+ return true;
+}
inline void fillHostLoggerEntryJson(std::string_view logEntryID,
std::string_view msg,