From 1e803dcc7a1d6391e8ae84b498509fe27fe7e523 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Thu, 20 Jun 2024 11:59:10 -0800 Subject: [PATCH] fix: reimplement crash logs written to file on disk (#4061) --- .../Recording/Monitors/SentryCrashMonitor.c | 1 - .../Monitors/SentryCrashMonitor_AppState.c | 1 - .../SentryCrashMonitor_CPPException.cpp | 1 - .../SentryCrashMonitor_MachException.c | 1 - .../Monitors/SentryCrashMonitor_NSException.m | 1 - .../Monitors/SentryCrashMonitor_Signal.c | 1 - .../Monitors/SentryCrashMonitor_System.m | 1 - Sources/SentryCrash/Recording/SentryCrash.m | 1 - Sources/SentryCrash/Recording/SentryCrashC.c | 14 +- .../Recording/SentryCrashCachedData.c | 1 - .../SentryCrash/Recording/SentryCrashReport.c | 1 - .../Recording/Tools/SentryCrashCPU.c | 1 - .../Recording/Tools/SentryCrashCPU_arm.c | 1 - .../Recording/Tools/SentryCrashCPU_arm64.c | 1 - .../Recording/Tools/SentryCrashCPU_x86_32.c | 1 - .../Recording/Tools/SentryCrashCPU_x86_64.c | 1 - .../Recording/Tools/SentryCrashDebug.c | 1 - .../Recording/Tools/SentryCrashFileUtils.c | 1 - .../Recording/Tools/SentryCrashLogger.c | 19 +- .../Recording/Tools/SentryCrashLogger.h | 298 ++++++++++-------- .../Tools/SentryCrashMachineContext.c | 1 - .../Recording/Tools/SentryCrashMemory.c | 1 - .../Recording/Tools/SentryCrashStackCursor.c | 1 - .../Tools/SentryCrashStackCursor_Backtrace.c | 1 - .../SentryCrashStackCursor_MachineContext.c | 1 - .../Tools/SentryCrashStackCursor_SelfThread.m | 1 - .../Recording/Tools/SentryCrashSysCtl.c | 1 - .../Recording/Tools/SentryCrashThread.c | 1 - .../Filters/SentryCrashReportFilterBasic.m | 1 - 29 files changed, 177 insertions(+), 180 deletions(-) diff --git a/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor.c b/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor.c index 37e229c4cc4..c825ffbab96 100644 --- a/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor.c +++ b/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor.c @@ -41,7 +41,6 @@ #include -// #define SentryCrashLogger_LocalLevel TRACE #include "SentryCrashLogger.h" // ============================================================================ diff --git a/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_AppState.c b/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_AppState.c index 0ed2e122597..da05126495a 100644 --- a/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_AppState.c +++ b/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_AppState.c @@ -31,7 +31,6 @@ #include "SentryCrashJSONCodec.h" #include "SentryCrashMonitorContext.h" -// #define SentryCrashLogger_LocalLevel TRACE #include "SentryCrashLogger.h" #include diff --git a/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_CPPException.cpp b/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_CPPException.cpp index f2400d5a5c4..e1beacc0316 100644 --- a/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_CPPException.cpp +++ b/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_CPPException.cpp @@ -30,7 +30,6 @@ #include "SentryCrashStackCursor_SelfThread.h" #include "SentryCrashThread.h" -// #define SentryCrashLogger_LocalLevel TRACE #include "SentryCrashLogger.h" #include diff --git a/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_MachException.c b/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_MachException.c index f66f55c8619..77180ad9901 100644 --- a/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_MachException.c +++ b/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_MachException.c @@ -34,7 +34,6 @@ #include "SentryCrashThread.h" #include "SentryInternalCDefines.h" -// #define SentryCrashLogger_LocalLevel TRACE #include "SentryCrashLogger.h" #if SentryCrashCRASH_HAS_MACH diff --git a/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_NSException.m b/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_NSException.m index d0afabd0754..b9a3bdd3f67 100644 --- a/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_NSException.m +++ b/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_NSException.m @@ -33,7 +33,6 @@ #include "SentryCrashThread.h" #import "SentryDependencyContainer.h" -// #define SentryCrashLogger_LocalLevel TRACE #import "SentryCrashLogger.h" // ============================================================================ diff --git a/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_Signal.c b/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_Signal.c index 39d17ffca71..32146b496bd 100644 --- a/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_Signal.c +++ b/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_Signal.c @@ -33,7 +33,6 @@ #include "SentryCrashStackCursor_MachineContext.h" #include "SentryCrashSystemCapabilities.h" -// #define SentryCrashLogger_LocalLevel TRACE #include "SentryCrashLogger.h" #if SentryCrashCRASH_HAS_SIGNAL diff --git a/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_System.m b/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_System.m index 7e796941ff7..5e7780a3ca5 100644 --- a/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_System.m +++ b/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_System.m @@ -34,7 +34,6 @@ #import "SentryCrashSysCtl.h" #import "SentryCrashSystemCapabilities.h" -// #define SentryCrashLogger_LocalLevel TRACE #import "SentryCrashLogger.h" #import "SentryDefines.h" diff --git a/Sources/SentryCrash/Recording/SentryCrash.m b/Sources/SentryCrash/Recording/SentryCrash.m index dd1b27d9237..8b299010b9b 100644 --- a/Sources/SentryCrash/Recording/SentryCrash.m +++ b/Sources/SentryCrash/Recording/SentryCrash.m @@ -42,7 +42,6 @@ #import "SentryNSNotificationCenterWrapper.h" #import -// #define SentryCrashLogger_LocalLevel TRACE #import "SentryCrashLogger.h" #if SENTRY_HAS_UIKIT diff --git a/Sources/SentryCrash/Recording/SentryCrashC.c b/Sources/SentryCrash/Recording/SentryCrashC.c index ff21ab1ffcf..a46ee91ef0b 100644 --- a/Sources/SentryCrash/Recording/SentryCrashC.c +++ b/Sources/SentryCrash/Recording/SentryCrashC.c @@ -39,7 +39,6 @@ #include "SentryCrashString.h" #include "SentryCrashSystemCapabilities.h" -// #define SentryCrashLogger_LocalLevel TRACE #include "SentryCrashLogger.h" #include @@ -54,6 +53,10 @@ /** True if SentryCrash has been installed. */ static volatile bool g_installed = 0; +#if SentryCrashLogger_CBufferSize > 0 +static char g_consoleLogPath[SentryCrashFU_MAX_PATH_LENGTH]; +#endif // SentryCrashLogger_CBufferSize > 0 + static SentryCrashMonitorType g_monitoring = SentryCrashMonitorTypeProductionSafeMinimal; static char g_lastCrashReportFilePath[SentryCrashFU_MAX_PATH_LENGTH]; static void (*g_saveScreenShot)(const char *) = 0; @@ -77,6 +80,10 @@ onCrash(struct SentryCrash_MonitorContext *monitorContext) SentryCrashLOG_DEBUG("Updating application state to note crash."); sentrycrashstate_notifyAppCrash(); +#if SentryCrashLogger_CBufferSize > 0 + monitorContext->consoleLogPath = g_consoleLogPath; +#endif // SentryCrashLogger_CBufferSize > 0 + if (monitorContext->crashedDuringCrashHandling) { sentrycrashreport_writeRecrashReport(monitorContext, g_lastCrashReportFilePath); } else { @@ -134,6 +141,11 @@ sentrycrash_install(const char *appName, const char *const installPath) snprintf(path, sizeof(path), "%s/Data/CrashState.json", installPath); sentrycrashstate_initialize(path); +#if SentryCrashLogger_CBufferSize > 0 + snprintf(g_consoleLogPath, sizeof(g_consoleLogPath), "%s/Data/ConsoleLog.txt", installPath); + sentrycrashlog_setLogFilename(g_consoleLogPath, true); +#endif // SentryCrashLogger_CBufferSize > 0 + sentrycrashccd_init(60); sentrycrashcm_setEventCallback(onCrash); diff --git a/Sources/SentryCrash/Recording/SentryCrashCachedData.c b/Sources/SentryCrash/Recording/SentryCrashCachedData.c index e366495ce3c..df4c9b5becf 100644 --- a/Sources/SentryCrash/Recording/SentryCrashCachedData.c +++ b/Sources/SentryCrash/Recording/SentryCrashCachedData.c @@ -26,7 +26,6 @@ #include "SentryCrashCachedData.h" #include "SentryInternalCDefines.h" -// #define SentryCrashLogger_LocalLevel TRACE #include "SentryCrashLogger.h" #include diff --git a/Sources/SentryCrash/Recording/SentryCrashReport.c b/Sources/SentryCrash/Recording/SentryCrashReport.c index 811369a2f3d..9c15aa2695a 100644 --- a/Sources/SentryCrash/Recording/SentryCrashReport.c +++ b/Sources/SentryCrash/Recording/SentryCrashReport.c @@ -48,7 +48,6 @@ #include "SentryCrashUUIDConversion.h" #include "SentryScopeSyncC.h" -// #define SentryCrashLogger_LocalLevel TRACE #include "SentryCrashLogger.h" #include diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashCPU.c b/Sources/SentryCrash/Recording/Tools/SentryCrashCPU.c index 52201766d04..f7a3f0139e4 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashCPU.c +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashCPU.c @@ -32,7 +32,6 @@ #include #include -// #define SentryCrashLogger_LocalLevel TRACE #include "SentryCrashLogger.h" const char * diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashCPU_arm.c b/Sources/SentryCrash/Recording/Tools/SentryCrashCPU_arm.c index 3a4a71878e5..1b307232d13 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashCPU_arm.c +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashCPU_arm.c @@ -33,7 +33,6 @@ # include "SentryCrashMachineContext_Apple.h" # include -// #define SentryCrashLogger_LocalLevel TRACE # include "SentryCrashLogger.h" static const char *g_registerNames[] = { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashCPU_arm64.c b/Sources/SentryCrash/Recording/Tools/SentryCrashCPU_arm64.c index d244494ddfb..3eef530df70 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashCPU_arm64.c +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashCPU_arm64.c @@ -33,7 +33,6 @@ # include "SentryCrashMachineContext_Apple.h" # include -// #define SentryCrashLogger_LocalLevel TRACE # include "SentryCrashLogger.h" # define KSPACStrippingMask_ARM64e 0x0000000fffffffff diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashCPU_x86_32.c b/Sources/SentryCrash/Recording/Tools/SentryCrashCPU_x86_32.c index c95ac6275fa..96a1cf7b355 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashCPU_x86_32.c +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashCPU_x86_32.c @@ -33,7 +33,6 @@ # include "SentryCrashMachineContext_Apple.h" # include -// #define SentryCrashLogger_LocalLevel TRACE # include "SentryCrashLogger.h" static const char *g_registerNames[] = { diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashCPU_x86_64.c b/Sources/SentryCrash/Recording/Tools/SentryCrashCPU_x86_64.c index aaca4b24b07..8e8fbff798a 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashCPU_x86_64.c +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashCPU_x86_64.c @@ -34,7 +34,6 @@ # include -// #define SentryCrashLogger_LocalLevel TRACE # include "SentryCrashLogger.h" static const char *g_registerNames[] = { "rax", "rbx", "rcx", "rdx", "rdi", "rsi", "rbp", "rsp", diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashDebug.c b/Sources/SentryCrash/Recording/Tools/SentryCrashDebug.c index 649f4e350cc..270c638aaab 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashDebug.c +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashDebug.c @@ -27,7 +27,6 @@ #include "SentryCrashDebug.h" -// #define SentryCrashLogger_LocalLevel TRACE #include "SentryCrashLogger.h" #include diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashFileUtils.c b/Sources/SentryCrash/Recording/Tools/SentryCrashFileUtils.c index 0380419b773..ac9a619e23f 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashFileUtils.c +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashFileUtils.c @@ -27,7 +27,6 @@ #include "SentryCrashFileUtils.h" -// #define SentryCrashLogger_LocalLevel TRACE #include "SentryCrashLogger.h" #include diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashLogger.c b/Sources/SentryCrash/Recording/Tools/SentryCrashLogger.c index 0b921437107..a24237f3807 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashLogger.c +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashLogger.c @@ -43,19 +43,6 @@ #define likely_if(x) if (__builtin_expect(x, 1)) #define unlikely_if(x) if (__builtin_expect(x, 0)) -/** The buffer size to use when writing log entries. - * - * If this value is > 0, any log entries that expand beyond this length will - * be truncated. - * If this value = 0, the logging system will dynamically allocate memory - * and never truncate. However, the log functions won't be async-safe. - * - * Unless you're logging from within signal handlers, it's safe to set it to 0. - */ -#ifndef SentryCrashLOGGER_CBufferSize -# define SentryCrashLOGGER_CBufferSize 1024 -#endif - /** Where console logs will be written */ static char g_logFilename[1024]; @@ -93,7 +80,7 @@ writeFmtToLog(const char *fmt, ...) va_end(args); } -#if SentryCrashLOGGER_CBufferSize > 0 +#if SentryCrashLogger_CBufferSize > 0 /** The file descriptor where log entries get written. */ static int g_fd = -1; @@ -120,7 +107,7 @@ writeFmtArgsToLog(const char *fmt, va_list args) unlikely_if(fmt == NULL) { writeToLog("(null)"); } else { - char buffer[SentryCrashLOGGER_CBufferSize]; + char buffer[SentryCrashLogger_CBufferSize]; vsnprintf(buffer, sizeof(buffer), fmt, args); writeToLog(buffer); } @@ -205,7 +192,7 @@ flushLog(void) fflush(g_file); } -#endif +#endif // if SentryCrashLogger_CBufferSize <= 0 // =========================================================================== #pragma mark - C - diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashLogger.h b/Sources/SentryCrash/Recording/Tools/SentryCrashLogger.h index 61bfbb4b48e..65a44ad807b 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashLogger.h +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashLogger.h @@ -129,115 +129,139 @@ * =============== * * The C logger changes its behavior depending on the value of the preprocessor - * define SentryCrashLogger_CBufferSize. + * define @c SentryCrashLogger_CBufferSize. * - * If SentryCrashLogger_CBufferSize is > 0, the C logger will behave in an + * If @c SentryCrashLogger_CBufferSize is > 0, the C logger will behave in an * async-safe manner, calling write() instead of printf(). Any log messages that * exceed the length specified by SentryCrashLogger_CBufferSize will be * truncated. * - * If SentryCrashLogger_CBufferSize == 0, the C logger will use printf(), and + * If @c SentryCrashLogger_CBufferSize == 0, the C logger will use printf(), and * there will be no limit on the log message length. * - * SentryCrashLogger_CBufferSize can only be set as a preprocessor define, and + * @c SentryCrashLogger_CBufferSize can only be set as a preprocessor define, and * will default to 1024 if not specified during compilation. */ +/** The buffer size to use when writing log entries. + * + * If this value is > 0, any log entries that expand beyond this length will + * be truncated. + * If this value = 0, the logging system will dynamically allocate memory + * and never truncate. However, the log functions won't be async-safe. + * + * Unless you're logging from within signal handlers, it's safe to set it to 0. + */ +#ifndef SentryCrashLogger_CBufferSize +#define SentryCrashLogger_CBufferSize 1024 +#endif + // ============================================================================ #pragma mark - (internal) - // ============================================================================ #ifndef HDR_SentryCrashLogger_h -# define HDR_SentryCrashLogger_h +#define HDR_SentryCrashLogger_h -# ifdef __cplusplus +#ifdef __cplusplus extern "C" { -# endif +#endif -# include +#include -# ifdef __OBJC__ +#ifdef __OBJC__ -# import +# import void i_sentrycrashlog_logObjC( const char *level, const char *file, int line, const char *function, CFStringRef fmt, ...); void i_sentrycrashlog_logObjCBasic(CFStringRef fmt, ...); -# define i_SentryCrashLOG_FULL(LEVEL, FILE, LINE, FUNCTION, FMT, ...) \ - i_sentrycrashlog_logObjC( \ - LEVEL, FILE, LINE, FUNCTION, (__bridge CFStringRef)FMT, ##__VA_ARGS__) -# define i_SentryCrashLOG_BASIC(FMT, ...) \ - i_sentrycrashlog_logObjCBasic((__bridge CFStringRef)FMT, ##__VA_ARGS__) +# define i_SentryCrashLOG_FULL(LEVEL, FILE, LINE, FUNCTION, FMT, ...) \ + i_sentrycrashlog_logObjC( \ + LEVEL, FILE, LINE, FUNCTION, (__bridge CFStringRef)FMT, ##__VA_ARGS__) +# define i_SentryCrashLOG_BASIC(FMT, ...) \ + i_sentrycrashlog_logObjCBasic((__bridge CFStringRef)FMT, ##__VA_ARGS__) -# else // __OBJC__ +#else // __OBJC__ void i_sentrycrashlog_logC( const char *level, const char *file, int line, const char *function, const char *fmt, ...); void i_sentrycrashlog_logCBasic(const char *fmt, ...); -# define i_SentryCrashLOG_FULL i_sentrycrashlog_logC -# define i_SentryCrashLOG_BASIC i_sentrycrashlog_logCBasic +# define i_SentryCrashLOG_FULL i_sentrycrashlog_logC +# define i_SentryCrashLOG_BASIC i_sentrycrashlog_logCBasic -# endif // __OBJC__ +#endif // __OBJC__ /* Back up any existing defines by the same name */ -# ifdef SentryCrash_NONE -# define SentryCrashLOG_BAK_NONE SentryCrash_NONE -# undef SentryCrash_NONE -# endif -# ifdef ERROR -# define SentryCrashLOG_BAK_ERROR ERROR -# undef ERROR -# endif -# ifdef WARN -# define SentryCrashLOG_BAK_WARN WARN -# undef WARN -# endif -# ifdef INFO -# define SentryCrashLOG_BAK_INFO INFO -# undef INFO -# endif -# ifdef DEBUG -# define SentryCrashLOG_BAK_DEBUG DEBUG -# undef DEBUG -# endif -# ifdef TRACE -# define SentryCrashLOG_BAK_TRACE TRACE -# undef TRACE -# endif - -# define SentryCrashLogger_Level_None 0 -# define SentryCrashLogger_Level_Error 10 -# define SentryCrashLogger_Level_Warn 20 -# define SentryCrashLogger_Level_Info 30 -# define SentryCrashLogger_Level_Debug 40 -# define SentryCrashLogger_Level_Trace 50 - -# define SentryCrash_NONE SentryCrashLogger_Level_None -# define ERROR SentryCrashLogger_Level_Error -# define WARN SentryCrashLogger_Level_Warn -# define INFO SentryCrashLogger_Level_Info -# define DEBUG SentryCrashLogger_Level_Debug -# define TRACE SentryCrashLogger_Level_Trace - -# ifndef SentryCrashLogger_Level -# define SentryCrashLogger_Level SentryCrashLogger_Level_Error -# endif - -# ifndef SentryCrashLogger_LocalLevel -# define SentryCrashLogger_LocalLevel SentryCrashLogger_Level_None -# endif - -# define a_SentryCrashLOG_FULL(LEVEL, FMT, ...) \ - i_SentryCrashLOG_FULL(LEVEL, __FILE__, __LINE__, __PRETTY_FUNCTION__, FMT, ##__VA_ARGS__) +#ifdef SentryCrash_NONE +# define SentryCrashLOG_BAK_NONE SentryCrash_NONE +# undef SentryCrash_NONE +#endif +#ifdef ERROR +# define SentryCrashLOG_BAK_ERROR ERROR +# undef ERROR +#endif +#ifdef WARN +# define SentryCrashLOG_BAK_WARN WARN +# undef WARN +#endif +#ifdef INFO +# define SentryCrashLOG_BAK_INFO INFO +# undef INFO +#endif +#ifdef DEBUG +# define SentryCrashLOG_BAK_DEBUG DEBUG +# undef DEBUG +#endif +#ifdef TRACE +# define SentryCrashLOG_BAK_TRACE TRACE +# undef TRACE +#endif + +#define SentryCrashLogger_Level_None 0 +#define SentryCrashLogger_Level_Error 10 +#define SentryCrashLogger_Level_Warn 20 +#define SentryCrashLogger_Level_Info 30 +#define SentryCrashLogger_Level_Debug 40 +#define SentryCrashLogger_Level_Trace 50 + +#define SentryCrash_NONE SentryCrashLogger_Level_None +#define ERROR SentryCrashLogger_Level_Error +#define WARN SentryCrashLogger_Level_Warn +#define INFO SentryCrashLogger_Level_Info +#define DEBUG SentryCrashLogger_Level_Debug +#define TRACE SentryCrashLogger_Level_Trace + +#ifndef SentryCrashLogger_Level +# define SentryCrashLogger_Level SentryCrashLogger_Level_Error +#endif + +#ifndef SentryCrashLogger_LocalLevel +# define SentryCrashLogger_LocalLevel SentryCrashLogger_Level_Trace +#endif + +#define a_SentryCrashLOG_FULL(LEVEL, FMT, ...) \ + i_SentryCrashLOG_FULL(LEVEL, __FILE__, __LINE__, __PRETTY_FUNCTION__, FMT, ##__VA_ARGS__) // ============================================================================ -# pragma mark - API - +#pragma mark - API - // ============================================================================ +/** Set the filename to log to. + * + * @param filename The file to write to (NULL = write to stdout). + * + * @param overwrite If true, overwrite the log file. + */ +bool sentrycrashlog_setLogFilename(const char *filename, bool overwrite); + +/** Clear the log file. */ +bool sentrycrashlog_clearLogFile(void); + /** Tests if the logger would print at the specified level. * * @param LEVEL The level to test for. One of: @@ -249,115 +273,115 @@ void i_sentrycrashlog_logCBasic(const char *fmt, ...); * * @return TRUE if the logger would print at the specified level. */ -# define SentryCrashLOG_PRINTS_AT_LEVEL(LEVEL) \ - (SentryCrashLogger_Level >= LEVEL || SentryCrashLogger_LocalLevel >= LEVEL) +#define SentryCrashLOG_PRINTS_AT_LEVEL(LEVEL) \ + (SentryCrashLogger_Level >= LEVEL || SentryCrashLogger_LocalLevel >= LEVEL) /** Log a message regardless of the log settings. * Normal version prints out full context. Basic version prints directly. * * @param FMT The format specifier, followed by its arguments. */ -# define SentryCrashLOG_ALWAYS(FMT, ...) a_SentryCrashLOG_FULL("FORCE", FMT, ##__VA_ARGS__) -# define SentryCrashLOGBASIC_ALWAYS(FMT, ...) i_SentryCrashLOG_BASIC(FMT, ##__VA_ARGS__) +#define SentryCrashLOG_ALWAYS(FMT, ...) a_SentryCrashLOG_FULL("FORCE", FMT, ##__VA_ARGS__) +#define SentryCrashLOGBASIC_ALWAYS(FMT, ...) i_SentryCrashLOG_BASIC(FMT, ##__VA_ARGS__) /** Log an error. * Normal version prints out full context. Basic version prints directly. * * @param FMT The format specifier, followed by its arguments. */ -# if SentryCrashLOG_PRINTS_AT_LEVEL(SentryCrashLogger_Level_Error) -# define SentryCrashLOG_ERROR(FMT, ...) a_SentryCrashLOG_FULL("ERROR", FMT, ##__VA_ARGS__) -# define SentryCrashLOGBASIC_ERROR(FMT, ...) i_SentryCrashLOG_BASIC(FMT, ##__VA_ARGS__) -# else -# define SentryCrashLOG_ERROR(FMT, ...) -# define SentryCrashLOGBASIC_ERROR(FMT, ...) -# endif +#if SentryCrashLOG_PRINTS_AT_LEVEL(SentryCrashLogger_Level_Error) +# define SentryCrashLOG_ERROR(FMT, ...) a_SentryCrashLOG_FULL("ERROR", FMT, ##__VA_ARGS__) +# define SentryCrashLOGBASIC_ERROR(FMT, ...) i_SentryCrashLOG_BASIC(FMT, ##__VA_ARGS__) +#else +# define SentryCrashLOG_ERROR(FMT, ...) +# define SentryCrashLOGBASIC_ERROR(FMT, ...) +#endif /** Log a warning. * Normal version prints out full context. Basic version prints directly. * * @param FMT The format specifier, followed by its arguments. */ -# if SentryCrashLOG_PRINTS_AT_LEVEL(SentryCrashLogger_Level_Warn) -# define SentryCrashLOG_WARN(FMT, ...) a_SentryCrashLOG_FULL("WARN ", FMT, ##__VA_ARGS__) -# define SentryCrashLOGBASIC_WARN(FMT, ...) i_SentryCrashLOG_BASIC(FMT, ##__VA_ARGS__) -# else -# define SentryCrashLOG_WARN(FMT, ...) -# define SentryCrashLOGBASIC_WARN(FMT, ...) -# endif +#if SentryCrashLOG_PRINTS_AT_LEVEL(SentryCrashLogger_Level_Warn) +# define SentryCrashLOG_WARN(FMT, ...) a_SentryCrashLOG_FULL("WARN ", FMT, ##__VA_ARGS__) +# define SentryCrashLOGBASIC_WARN(FMT, ...) i_SentryCrashLOG_BASIC(FMT, ##__VA_ARGS__) +#else +# define SentryCrashLOG_WARN(FMT, ...) +# define SentryCrashLOGBASIC_WARN(FMT, ...) +#endif /** Log an info message. * Normal version prints out full context. Basic version prints directly. * * @param FMT The format specifier, followed by its arguments. */ -# if SentryCrashLOG_PRINTS_AT_LEVEL(SentryCrashLogger_Level_Info) -# define SentryCrashLOG_INFO(FMT, ...) a_SentryCrashLOG_FULL("INFO ", FMT, ##__VA_ARGS__) -# define SentryCrashLOGBASIC_INFO(FMT, ...) i_SentryCrashLOG_BASIC(FMT, ##__VA_ARGS__) -# else -# define SentryCrashLOG_INFO(FMT, ...) -# define SentryCrashLOGBASIC_INFO(FMT, ...) -# endif +#if SentryCrashLOG_PRINTS_AT_LEVEL(SentryCrashLogger_Level_Info) +# define SentryCrashLOG_INFO(FMT, ...) a_SentryCrashLOG_FULL("INFO ", FMT, ##__VA_ARGS__) +# define SentryCrashLOGBASIC_INFO(FMT, ...) i_SentryCrashLOG_BASIC(FMT, ##__VA_ARGS__) +#else +# define SentryCrashLOG_INFO(FMT, ...) +# define SentryCrashLOGBASIC_INFO(FMT, ...) +#endif /** Log a debug message. * Normal version prints out full context. Basic version prints directly. * * @param FMT The format specifier, followed by its arguments. */ -# if SentryCrashLOG_PRINTS_AT_LEVEL(SentryCrashLogger_Level_Debug) -# define SentryCrashLOG_DEBUG(FMT, ...) a_SentryCrashLOG_FULL("DEBUG", FMT, ##__VA_ARGS__) -# define SentryCrashLOGBASIC_DEBUG(FMT, ...) i_SentryCrashLOG_BASIC(FMT, ##__VA_ARGS__) -# else -# define SentryCrashLOG_DEBUG(FMT, ...) -# define SentryCrashLOGBASIC_DEBUG(FMT, ...) -# endif +#if SentryCrashLOG_PRINTS_AT_LEVEL(SentryCrashLogger_Level_Debug) +# define SentryCrashLOG_DEBUG(FMT, ...) a_SentryCrashLOG_FULL("DEBUG", FMT, ##__VA_ARGS__) +# define SentryCrashLOGBASIC_DEBUG(FMT, ...) i_SentryCrashLOG_BASIC(FMT, ##__VA_ARGS__) +#else +# define SentryCrashLOG_DEBUG(FMT, ...) +# define SentryCrashLOGBASIC_DEBUG(FMT, ...) +#endif /** Log a trace message. * Normal version prints out full context. Basic version prints directly. * * @param FMT The format specifier, followed by its arguments. */ -# if SentryCrashLOG_PRINTS_AT_LEVEL(SentryCrashLogger_Level_Trace) -# define SentryCrashLOG_TRACE(FMT, ...) a_SentryCrashLOG_FULL("TRACE", FMT, ##__VA_ARGS__) -# define SentryCrashLOGBASIC_TRACE(FMT, ...) i_SentryCrashLOG_BASIC(FMT, ##__VA_ARGS__) -# else -# define SentryCrashLOG_TRACE(FMT, ...) -# define SentryCrashLOGBASIC_TRACE(FMT, ...) -# endif +#if SentryCrashLOG_PRINTS_AT_LEVEL(SentryCrashLogger_Level_Trace) +# define SentryCrashLOG_TRACE(FMT, ...) a_SentryCrashLOG_FULL("TRACE", FMT, ##__VA_ARGS__) +# define SentryCrashLOGBASIC_TRACE(FMT, ...) i_SentryCrashLOG_BASIC(FMT, ##__VA_ARGS__) +#else +# define SentryCrashLOG_TRACE(FMT, ...) +# define SentryCrashLOGBASIC_TRACE(FMT, ...) +#endif // ============================================================================ -# pragma mark - (internal) - +#pragma mark - (internal) - // ============================================================================ /* Put everything back to the way we found it. */ -# undef ERROR -# ifdef SentryCrashLOG_BAK_ERROR -# define ERROR SentryCrashLOG_BAK_ERROR -# undef SentryCrashLOG_BAK_ERROR -# endif -# undef WARNING -# ifdef SentryCrashLOG_BAK_WARN -# define WARNING SentryCrashLOG_BAK_WARN -# undef SentryCrashLOG_BAK_WARN -# endif -# undef INFO -# ifdef SentryCrashLOG_BAK_INFO -# define INFO SentryCrashLOG_BAK_INFO -# undef SentryCrashLOG_BAK_INFO -# endif -# undef DEBUG -# ifdef SentryCrashLOG_BAK_DEBUG -# define DEBUG SentryCrashLOG_BAK_DEBUG -# undef SentryCrashLOG_BAK_DEBUG -# endif -# undef TRACE -# ifdef SentryCrashLOG_BAK_TRACE -# define TRACE SentryCrashLOG_BAK_TRACE -# undef SentryCrashLOG_BAK_TRACE -# endif - -# ifdef __cplusplus +#undef ERROR +#ifdef SentryCrashLOG_BAK_ERROR +# define ERROR SentryCrashLOG_BAK_ERROR +# undef SentryCrashLOG_BAK_ERROR +#endif +#undef WARNING +#ifdef SentryCrashLOG_BAK_WARN +# define WARNING SentryCrashLOG_BAK_WARN +# undef SentryCrashLOG_BAK_WARN +#endif +#undef INFO +#ifdef SentryCrashLOG_BAK_INFO +# define INFO SentryCrashLOG_BAK_INFO +# undef SentryCrashLOG_BAK_INFO +#endif +#undef DEBUG +#ifdef SentryCrashLOG_BAK_DEBUG +# define DEBUG SentryCrashLOG_BAK_DEBUG +# undef SentryCrashLOG_BAK_DEBUG +#endif +#undef TRACE +#ifdef SentryCrashLOG_BAK_TRACE +# define TRACE SentryCrashLOG_BAK_TRACE +# undef SentryCrashLOG_BAK_TRACE +#endif + +#ifdef __cplusplus } -# endif +#endif #endif // HDR_SentryCrashLogger_h diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashMachineContext.c b/Sources/SentryCrash/Recording/Tools/SentryCrashMachineContext.c index b54091fad6d..67afc49d028 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashMachineContext.c +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashMachineContext.c @@ -35,7 +35,6 @@ #include -// #define SentryCrashLogger_LocalLevel TRACE #include "SentryCrashLogger.h" #ifdef __arm64__ diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashMemory.c b/Sources/SentryCrash/Recording/Tools/SentryCrashMemory.c index 763a9b1fe29..4a0addd0cb2 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashMemory.c +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashMemory.c @@ -27,7 +27,6 @@ #include "SentryCrashMemory.h" -// #define SentryCrashLogger_LocalLevel TRACE #include "SentryCrashLogger.h" #include <_types/_uint8_t.h> diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashStackCursor.c b/Sources/SentryCrash/Recording/Tools/SentryCrashStackCursor.c index 519d76bf1c7..03dbfd1e4d1 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashStackCursor.c +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashStackCursor.c @@ -28,7 +28,6 @@ #include "SentryCrashSymbolicator.h" #include -// #define SentryCrashLogger_LocalLevel TRACE #include "SentryCrashLogger.h" static bool diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashStackCursor_Backtrace.c b/Sources/SentryCrash/Recording/Tools/SentryCrashStackCursor_Backtrace.c index 76040734378..27c222184ef 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashStackCursor_Backtrace.c +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashStackCursor_Backtrace.c @@ -26,7 +26,6 @@ #include "SentryCrashStackCursor_Backtrace.h" #include "SentryCrashCPU.h" -// #define SentryCrashLogger_LocalLevel TRACE #include "SentryCrashLogger.h" static bool diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashStackCursor_MachineContext.c b/Sources/SentryCrash/Recording/Tools/SentryCrashStackCursor_MachineContext.c index 2fc998ecde0..9a53dba5cb1 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashStackCursor_MachineContext.c +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashStackCursor_MachineContext.c @@ -30,7 +30,6 @@ #include -#define SentryCrashLogger_LocalLevel TRACE #include "SentryCrashLogger.h" /** Represents an entry in a frame list. diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashStackCursor_SelfThread.m b/Sources/SentryCrash/Recording/Tools/SentryCrashStackCursor_SelfThread.m index 2b4d0f179a0..cfca87ee0fe 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashStackCursor_SelfThread.m +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashStackCursor_SelfThread.m @@ -28,7 +28,6 @@ #import "SentryLog.h" #include -// #define SentryCrashLogger_LocalLevel TRACE #include "SentryCrashLogger.h" #define MAX_BACKTRACE_LENGTH \ diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashSysCtl.c b/Sources/SentryCrash/Recording/Tools/SentryCrashSysCtl.c index 7a6265837f4..79ff6467530 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashSysCtl.c +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashSysCtl.c @@ -27,7 +27,6 @@ #include "SentryCrashSysCtl.h" -// #define SentryCrashLogger_LocalLevel TRACE #include "SentryCrashLogger.h" #include diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashThread.c b/Sources/SentryCrash/Recording/Tools/SentryCrashThread.c index db829421433..8e4c3d20329 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashThread.c +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashThread.c @@ -30,7 +30,6 @@ #include "SentryCrashMemory.h" #include "SentryCrashSystemCapabilities.h" -// #define SentryCrashLogger_LocalLevel TRACE #include "SentryCrashLogger.h" #include diff --git a/Sources/SentryCrash/Reporting/Filters/SentryCrashReportFilterBasic.m b/Sources/SentryCrash/Reporting/Filters/SentryCrashReportFilterBasic.m index a320fb44be3..03d7dadff63 100644 --- a/Sources/SentryCrash/Reporting/Filters/SentryCrashReportFilterBasic.m +++ b/Sources/SentryCrash/Reporting/Filters/SentryCrashReportFilterBasic.m @@ -30,7 +30,6 @@ #import "SentryCrashVarArgs.h" #import "SentryDictionaryDeepSearch.h" -// #define SentryCrashLogger_LocalLevel TRACE #import "SentryCrashLogger.h" @implementation SentryCrashReportFilterPassthrough