summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--http/http_client.hpp1
-rw-r--r--http/logging.hpp41
-rw-r--r--http/verb.hpp1
-rw-r--r--include/async_resolve.hpp1
-rw-r--r--include/ossl_random.hpp1
-rw-r--r--redfish-core/include/registries.hpp1
6 files changed, 32 insertions, 14 deletions
diff --git a/http/http_client.hpp b/http/http_client.hpp
index ac231b42e7..0bfb3818df 100644
--- a/http/http_client.hpp
+++ b/http/http_client.hpp
@@ -44,7 +44,6 @@
#include <cstdlib>
#include <functional>
-#include <iostream>
#include <memory>
#include <queue>
#include <string>
diff --git a/http/logging.hpp b/http/logging.hpp
index cf908771bb..4b9eab967c 100644
--- a/http/logging.hpp
+++ b/http/logging.hpp
@@ -65,7 +65,7 @@ const void* logPtr(T p)
}
template <LogLevel level, typename... Args>
-inline void vlog(std::format_string<Args...> format, Args... args,
+inline void vlog(std::format_string<Args...>&& format, Args&&... args,
const std::source_location& loc) noexcept
{
if constexpr (bmcwebCurrentLoggingLevel < level)
@@ -78,9 +78,27 @@ inline void vlog(std::format_string<Args...> format, Args... args,
constexpr std::string_view levelString = mapLogLevelFromName[stringIndex];
std::string_view filename = loc.file_name();
filename = filename.substr(filename.rfind('/') + 1);
- std::cout << std::format("[{} {}:{}] ", levelString, filename, loc.line())
- << std::format(format, std::forward<Args>(args)...) << '\n'
- << std::flush;
+ std::string logLocation;
+ logLocation = std::format("[{} {}:{}] ", levelString, filename, loc.line());
+ try
+ {
+ // TODO, multiple static analysis tools flag that this could potentially
+ // throw Based on the documentation, it shouldn't throw, so long as none
+ // of the formatters throw, so unclear at this point why this try/catch
+ // is required, but add it to silence the static analysis tools.
+ logLocation += std::format(std::move(format),
+ std::forward<Args>(args)...);
+ }
+ catch (const std::format_error& /*error*/)
+ {
+ logLocation += "Failed to format";
+ // Nothing more we can do here if logging is broken.
+ }
+ logLocation += '\n';
+ // Intentionally ignore error return.
+ fwrite(logLocation.data(), sizeof(std::string::value_type),
+ logLocation.size(), stdout);
+ fflush(stdout);
}
} // namespace crow
@@ -92,7 +110,8 @@ struct BMCWEB_LOG_CRITICAL
const std::source_location& loc =
std::source_location::current()) noexcept
{
- crow::vlog<crow::LogLevel::Critical, Args...>(format, args..., loc);
+ crow::vlog<crow::LogLevel::Critical, Args...>(
+ std::move(format), std::forward<Args>(args)..., loc);
}
};
@@ -104,7 +123,8 @@ struct BMCWEB_LOG_ERROR
const std::source_location& loc =
std::source_location::current()) noexcept
{
- crow::vlog<crow::LogLevel::Error, Args...>(format, args..., loc);
+ crow::vlog<crow::LogLevel::Error, Args...>(
+ std::move(format), std::forward<Args>(args)..., loc);
}
};
@@ -116,7 +136,8 @@ struct BMCWEB_LOG_WARNING
const std::source_location& loc =
std::source_location::current()) noexcept
{
- crow::vlog<crow::LogLevel::Warning, Args...>(format, args..., loc);
+ crow::vlog<crow::LogLevel::Warning, Args...>(
+ std::move(format), std::forward<Args>(args)..., loc);
}
};
@@ -128,7 +149,8 @@ struct BMCWEB_LOG_INFO
const std::source_location& loc =
std::source_location::current()) noexcept
{
- crow::vlog<crow::LogLevel::Info, Args...>(format, args..., loc);
+ crow::vlog<crow::LogLevel::Info, Args...>(
+ std::move(format), std::forward<Args>(args)..., loc);
}
};
@@ -140,7 +162,8 @@ struct BMCWEB_LOG_DEBUG
const std::source_location& loc =
std::source_location::current()) noexcept
{
- crow::vlog<crow::LogLevel::Debug, Args...>(format, args..., loc);
+ crow::vlog<crow::LogLevel::Debug, Args...>(
+ std::move(format), std::forward<Args>(args)..., loc);
}
};
diff --git a/http/verb.hpp b/http/verb.hpp
index 5859d10b0d..b96008de18 100644
--- a/http/verb.hpp
+++ b/http/verb.hpp
@@ -2,7 +2,6 @@
#include <boost/beast/http/verb.hpp>
-#include <iostream>
#include <optional>
#include <string_view>
diff --git a/include/async_resolve.hpp b/include/async_resolve.hpp
index 2d9899d1a4..dbc0cfc749 100644
--- a/include/async_resolve.hpp
+++ b/include/async_resolve.hpp
@@ -8,7 +8,6 @@
#include <sdbusplus/message.hpp>
#include <charconv>
-#include <iostream>
#include <memory>
namespace async_resolve
diff --git a/include/ossl_random.hpp b/include/ossl_random.hpp
index 0e28944d83..4d4bc04a06 100644
--- a/include/ossl_random.hpp
+++ b/include/ossl_random.hpp
@@ -7,7 +7,6 @@ extern "C"
#include <openssl/rand.h>
}
-#include <iostream>
#include <limits>
#include <string>
diff --git a/redfish-core/include/registries.hpp b/redfish-core/include/registries.hpp
index bad31c4324..b0ddb68fdd 100644
--- a/redfish-core/include/registries.hpp
+++ b/redfish-core/include/registries.hpp
@@ -20,7 +20,6 @@
#include <array>
#include <charconv>
#include <cstddef>
-#include <iostream>
#include <numeric>
#include <span>
#include <string>