Skip to content

Commit

Permalink
fix: reimplement crash logs written to file on disk (#4061)
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight authored Jun 20, 2024
1 parent 0759ae9 commit 1e803dc
Show file tree
Hide file tree
Showing 29 changed files with 177 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

#include <memory.h>

// #define SentryCrashLogger_LocalLevel TRACE
#include "SentryCrashLogger.h"

// ============================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "SentryCrashJSONCodec.h"
#include "SentryCrashMonitorContext.h"

// #define SentryCrashLogger_LocalLevel TRACE
#include "SentryCrashLogger.h"

#include <errno.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "SentryCrashStackCursor_SelfThread.h"
#include "SentryCrashThread.h"

// #define SentryCrashLogger_LocalLevel TRACE
#include "SentryCrashLogger.h"

#include <cxxabi.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include "SentryCrashThread.h"
#include "SentryInternalCDefines.h"

// #define SentryCrashLogger_LocalLevel TRACE
#include "SentryCrashLogger.h"

#if SentryCrashCRASH_HAS_MACH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "SentryCrashThread.h"
#import "SentryDependencyContainer.h"

// #define SentryCrashLogger_LocalLevel TRACE
#import "SentryCrashLogger.h"

// ============================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "SentryCrashStackCursor_MachineContext.h"
#include "SentryCrashSystemCapabilities.h"

// #define SentryCrashLogger_LocalLevel TRACE
#include "SentryCrashLogger.h"

#if SentryCrashCRASH_HAS_SIGNAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#import "SentryCrashSysCtl.h"
#import "SentryCrashSystemCapabilities.h"

// #define SentryCrashLogger_LocalLevel TRACE
#import "SentryCrashLogger.h"

#import "SentryDefines.h"
Expand Down
1 change: 0 additions & 1 deletion Sources/SentryCrash/Recording/SentryCrash.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#import "SentryNSNotificationCenterWrapper.h"
#import <SentryNSDataUtils.h>

// #define SentryCrashLogger_LocalLevel TRACE
#import "SentryCrashLogger.h"

#if SENTRY_HAS_UIKIT
Expand Down
14 changes: 13 additions & 1 deletion Sources/SentryCrash/Recording/SentryCrashC.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include "SentryCrashString.h"
#include "SentryCrashSystemCapabilities.h"

// #define SentryCrashLogger_LocalLevel TRACE
#include "SentryCrashLogger.h"

#include <inttypes.h>
Expand All @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion Sources/SentryCrash/Recording/SentryCrashCachedData.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "SentryCrashCachedData.h"
#include "SentryInternalCDefines.h"

// #define SentryCrashLogger_LocalLevel TRACE
#include "SentryCrashLogger.h"

#include <errno.h>
Expand Down
1 change: 0 additions & 1 deletion Sources/SentryCrash/Recording/SentryCrashReport.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#include "SentryCrashUUIDConversion.h"
#include "SentryScopeSyncC.h"

// #define SentryCrashLogger_LocalLevel TRACE
#include "SentryCrashLogger.h"

#include <errno.h>
Expand Down
1 change: 0 additions & 1 deletion Sources/SentryCrash/Recording/Tools/SentryCrashCPU.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <mach-o/arch.h>
#include <mach/mach.h>

// #define SentryCrashLogger_LocalLevel TRACE
#include "SentryCrashLogger.h"

const char *
Expand Down
1 change: 0 additions & 1 deletion Sources/SentryCrash/Recording/Tools/SentryCrashCPU_arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
# include "SentryCrashMachineContext_Apple.h"
# include <stdlib.h>

// #define SentryCrashLogger_LocalLevel TRACE
# include "SentryCrashLogger.h"

static const char *g_registerNames[] = { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9",
Expand Down
1 change: 0 additions & 1 deletion Sources/SentryCrash/Recording/Tools/SentryCrashCPU_arm64.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
# include "SentryCrashMachineContext_Apple.h"
# include <stdlib.h>

// #define SentryCrashLogger_LocalLevel TRACE
# include "SentryCrashLogger.h"

# define KSPACStrippingMask_ARM64e 0x0000000fffffffff
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
# include "SentryCrashMachineContext_Apple.h"
# include <stdlib.h>

// #define SentryCrashLogger_LocalLevel TRACE
# include "SentryCrashLogger.h"

static const char *g_registerNames[] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

# include <stdlib.h>

// #define SentryCrashLogger_LocalLevel TRACE
# include "SentryCrashLogger.h"

static const char *g_registerNames[] = { "rax", "rbx", "rcx", "rdx", "rdi", "rsi", "rbp", "rsp",
Expand Down
1 change: 0 additions & 1 deletion Sources/SentryCrash/Recording/Tools/SentryCrashDebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

#include "SentryCrashDebug.h"

// #define SentryCrashLogger_LocalLevel TRACE
#include "SentryCrashLogger.h"

#include <errno.h>
Expand Down
1 change: 0 additions & 1 deletion Sources/SentryCrash/Recording/Tools/SentryCrashFileUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

#include "SentryCrashFileUtils.h"

// #define SentryCrashLogger_LocalLevel TRACE
#include "SentryCrashLogger.h"

#include <dirent.h>
Expand Down
19 changes: 3 additions & 16 deletions Sources/SentryCrash/Recording/Tools/SentryCrashLogger.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -205,7 +192,7 @@ flushLog(void)
fflush(g_file);
}

#endif
#endif // if SentryCrashLogger_CBufferSize <= 0

// ===========================================================================
#pragma mark - C -
Expand Down
Loading

0 comments on commit 1e803dc

Please sign in to comment.