Sentry: more macro replacements

This commit is contained in:
Lion Kortlepel
2021-08-12 01:24:48 +02:00
committed by Lion
parent 0f9a994c10
commit ff3cbebac0
5 changed files with 28 additions and 18 deletions

View File

@@ -1,6 +1,9 @@
#include "TSentry.h"
#include "Common.h"
#include <sentry.h>
#include <sstream>
TSentry::TSentry(const std::string& SentryUrl) {
if (SentryUrl.empty()) {
mValid = false;
@@ -30,40 +33,46 @@ void TSentry::PrintWelcome() {
}
void TSentry::SetupUser() {
if (!mValid) {
return;
}
sentry_value_t user = sentry_value_new_object();
sentry_value_set_by_key(user, "id", sentry_value_new_string(Application::Settings.Key.c_str()));
sentry_set_user(user);
}
void TSentry::Log(sentry_level_t level, const std::string& logger, const std::string& text) {
void TSentry::Log(SentryLevel level, const std::string& logger, const std::string& text) {
if (!mValid) {
return;
}
SetContext("threads", { { "thread-name", ThreadName(true) } });
auto Msg = sentry_value_new_message_event(level, logger.c_str(), text.c_str());
auto Msg = sentry_value_new_message_event(sentry_level_t(level), logger.c_str(), text.c_str());
sentry_capture_event(Msg);
sentry_remove_transaction();
}
void TSentry::LogError(const std::string& text, const std::string& file, const std::string& line) {
if (!mValid) {
return;
}
SetTransaction(file + ":" + line);
Log(SENTRY_LEVEL_ERROR, "default", file + ": " + text);
Log(SentryLevel::Error, "default", file + ": " + text);
}
void TSentry::SetContext(const std::string& context_name, const std::unordered_map<std::string, std::string>& map) {
if (!mValid) {
return;
}
mContext = sentry_value_new_object();
auto ctx = sentry_value_new_object();
for (const auto& pair : map) {
std::string key = pair.first;
if (key == "type") {
// `type` is reserved
key = "_type";
}
sentry_value_set_by_key(mContext, key.c_str(), sentry_value_new_string(pair.second.c_str()));
sentry_value_set_by_key(ctx, key.c_str(), sentry_value_new_string(pair.second.c_str()));
}
sentry_set_context(context_name.c_str(), mContext);
sentry_set_context(context_name.c_str(), ctx);
}
void TSentry::LogException(const std::exception& e, const std::string& file, const std::string& line) {
@@ -71,7 +80,7 @@ void TSentry::LogException(const std::exception& e, const std::string& file, con
return;
}
SetTransaction(file + ":" + line);
Log(SENTRY_LEVEL_FATAL, "exceptions", std::string(e.what()) + " @ " + file + ":" + line);
Log(SentryLevel::Fatal, "exceptions", std::string(e.what()) + " @ " + file + ":" + line);
}
void TSentry::LogAssert(const std::string& condition_string, const std::string& file, const std::string& line, const std::string& function) {
@@ -81,7 +90,7 @@ void TSentry::LogAssert(const std::string& condition_string, const std::string&
SetTransaction(file + ":" + line + ":" + function);
std::stringstream ss;
ss << "\"" << condition_string << "\" failed @ " << file << ":" << line;
Log(SENTRY_LEVEL_FATAL, "asserts", ss.str());
Log(SentryLevel::Fatal, "asserts", ss.str());
}
void TSentry::AddErrorBreadcrumb(const std::string& msg, const std::string& file, const std::string& line) {