Integrate sentry-native crash reporting

This commit is contained in:
Luke Street 2021-04-04 18:20:48 -04:00
parent 17aa25cfa9
commit 0e3fe3e766
5 changed files with 53 additions and 2 deletions

3
.gitmodules vendored
View File

@ -1,3 +1,6 @@
[submodule "fmt"]
path = fmt
url = https://github.com/fmtlib/fmt
[submodule "sentry"]
path = sentry
url = git@github.com:getsentry/sentry-native.git

View File

@ -15,7 +15,19 @@ add_library(logvisor
lib/logvisor.cpp
include/logvisor/logvisor.hpp)
target_link_libraries(logvisor PUBLIC fmt)
if ("${SENTRY_DSN}" STREQUAL "")
message(STATUS "SENTRY_DSN not set, not enabling Sentry")
target_compile_definitions(logvisor PUBLIC SENTRY_ENABLED=0)
set(SENTRY_LIB "")
else()
message(STATUS "Enabling Sentry integration")
add_subdirectory(sentry)
target_compile_definitions(logvisor PUBLIC SENTRY_ENABLED=1)
target_compile_definitions(logvisor PRIVATE SENTRY_DSN="${SENTRY_DSN}")
set(SENTRY_LIB sentry)
endif()
target_link_libraries(logvisor PUBLIC fmt ${SENTRY_LIB})
if(NX)
target_link_libraries(logvisor PUBLIC debug nxd optimized nx)
else()
@ -33,7 +45,7 @@ set(config_install_dir "lib/cmake/logvisor")
# Associate target with export
install(
TARGETS logvisor fmt
TARGETS logvisor fmt ${SENTRY_LIB}
EXPORT logvisorTargets
ARCHIVE DESTINATION "lib"
INCLUDES DESTINATION include # This sets the INTERFACE_INCLUDE_DIRECTORIES property of the target.

View File

@ -153,6 +153,16 @@ void RegisterFileLogger(const char* filepath);
*/
void RegisterStandardExceptions();
#if SENTRY_ENABLED
/**
* @brief Register Sentry crash reporting & logging.
* @param appName The application name
* @param appVersion The application version
* @param cacheDir Directory for Sentry cache files
*/
void RegisterSentry(const char* appName, const char* appVersion, const char* cacheDir);
#endif
#if _WIN32
/**
* @brief Spawn an application-owned cmd.exe window for displaying console output

View File

@ -34,6 +34,10 @@
#include <csignal>
#include "logvisor/logvisor.hpp"
#if SENTRY_ENABLED
#include <sentry.h>
#endif
/* ANSI sequences */
#define RED "\x1b[1;31m"
#define YELLOW "\x1b[1;33m"
@ -737,6 +741,27 @@ void RegisterStandardExceptions() {
signal(SIGFPE, AbortHandler);
}
#if SENTRY_ENABLED
void RegisterSentry(const char* appName, const char* appVersion, const char* cacheDir) {
sentry_options_t *options = sentry_options_new();
sentry_options_set_database_path(options, cacheDir);
sentry_options_set_auto_session_tracking(options, true);
sentry_options_set_symbolize_stacktraces(options, true);
sentry_options_set_dsn(options, SENTRY_DSN);
#ifdef NDEBUG
sentry_options_set_environment(options, "release");
#else
sentry_options_set_environment(options, "debug");
#endif
std::string release = fmt::format(FMT_STRING("{}@{}"), appName, appVersion);
sentry_options_set_release(options, release.c_str());
sentry_init(options);
}
#endif
struct FileLogger : public ILogger {
FILE* fp = nullptr;
FileLogger(uint64_t typeHash) : ILogger(typeHash) {}

1
sentry Submodule

@ -0,0 +1 @@
Subproject commit aee5dc1a55dee01477f20016c197084a501db0de