Skip to content

Commit

Permalink
fix: log plugin log id
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyTWF committed Apr 14, 2024
1 parent 8fdf15b commit b199bd9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
18 changes: 13 additions & 5 deletions src/utils/log/ApiLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ namespace UKControllerPluginUtils::Log {

struct ApiLogger::Impl
{
[[nodiscard]] auto CreatePayloadNoMetadata(const std::string& type, const std::string& message) const
-> nlohmann::json
[[nodiscard]] auto
CreatePayloadNoMetadata(const std::string& type, const std::string& message) const -> nlohmann::json
{
return {{"type", type}, {"message", message}, {"metadata", PluginVersionMetadata().dump()}};
}

[[nodiscard]] auto
CreatePayload(const std::string& type, const std::string& message, const nlohmann::json& metadata) const
-> nlohmann::json
[[nodiscard]] auto CreatePayload(
const std::string& type, const std::string& message, const nlohmann::json& metadata) const -> nlohmann::json
{
auto metadataWithVersion = PluginVersionMetadata();
metadataWithVersion.update(metadata);
Expand All @@ -31,6 +30,15 @@ namespace UKControllerPluginUtils::Log {
{
ApiRequest()
.Post("plugin/logs", data)
.Then([](const UKControllerPluginUtils::Api::Response& response) {
const auto data = response.Data();
if (!data.is_object() || !data.contains("id") || !data["id"].is_string()) {
LogError("Failed to send log to API, response was not as expected");
return;
}

LogInfo("Log sent to API with ID " + data["id"].get<std::string>());
})
.Catch([](const Api::ApiRequestException& exception) {
LogError(
"Failed to send log to API, status code was " +
Expand Down
1 change: 0 additions & 1 deletion src/utils/log/LoggerFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ void LogFatalExceptionAndRethrow(const std::string& source, const std::exception

try {
ApiLogger().Log("FATAL_EXCEPTION", exceptionMessage);
throw;
} catch (const std::exception& e) {
LogCritical("Exception caught in LogFatalExceptionAndRethrow: " + std::string(e.what()));
}
Expand Down

0 comments on commit b199bd9

Please sign in to comment.