Skip to content

Commit

Permalink
DEBUG: file logging
Browse files Browse the repository at this point in the history
  • Loading branch information
tmolitor-stud-tu committed Jan 3, 2025
1 parent f57a584 commit 418c3b9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
7 changes: 7 additions & 0 deletions Monal/Classes/DebugView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ struct CrashTestingView: View {
print(delegate.unsafelyUnwrapped.audiovisualTypes())

}
Button("MLAssert Crash") {
HelperTools.flushLogs(withTimeout: 0.100)
MLAssert(false, "MLAssert_example1")
}
Button("MLAssert Crash without flush") {
MLAssert(false, "MLAssert_example2")
}
Button("Assertion Crash") {
HelperTools.flushLogs(withTimeout: 0.100)
assert(false)
Expand Down
53 changes: 39 additions & 14 deletions Monal/Classes/HelperTools.m
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,11 @@ void logException(NSException* exception)
NSString* prefix = @"CRASH";
#endif
//log error and flush all logs
DDLogWarn(@"Crash pending!!!");
[DDLog flushLog];
DDLogError(@"*****************\n%@(%@): %@\nUserInfo: %@\nStack Trace: %@", prefix, [exception name], [exception reason], [exception userInfo], [exception callStackSymbols]);
[DDLog flushLog];
DDLogWarn(@"Crash logged!!!");
[HelperTools flushLogsWithTimeout:0.250];
}

Expand All @@ -286,11 +288,11 @@ void uncaughtExceptionHandler(NSException* exception)
logException(exception);

//don't report that crash through KSCrash if the debugger is active
if(isDebugerActive())
{
DDLogError(@"Not reporting crash through KSCrash: debugger is active!");
return;
}
// if(isDebugerActive())
// {
// DDLogError(@"Not reporting crash through KSCrash: debugger is active!");
// return;
// }

//make sure this crash will be recorded by kscrash using the NSException rather than the c++ exception thrown by the objc runtime
//this will make sure that the stacktrace matches the objc exception rather than being a top level c++ stacktrace
Expand Down Expand Up @@ -598,11 +600,12 @@ +(void) initSystem
if(enableDefaultLogAndCrashFramework)
{
[self configureLogging];
[self installExceptionHandler];
//don't install KSCrash if the debugger is active
if(!isDebugerActive())
[self installCrashHandler];
else
DDLogWarn(@"Not installing crash handler: debugger is active!");
//if(!isDebugerActive())
//[self installCrashHandler];
// else
// DDLogWarn(@"Not installing crash handler: debugger is active!");
[self installExceptionHandler];
}
else
Expand Down Expand Up @@ -2220,6 +2223,8 @@ +(void) configureXcodeLogging

+(void) configureLogging
{
NSError* error;

//network logger (start as early as possible)
MLUDPLogger* udpLogger = [MLUDPLogger new];
[DDLog addLogger:udpLogger];
Expand All @@ -2233,10 +2238,17 @@ +(void) configureLogging
printf("stdout redirection complete...");

//redirect apple system logs, too
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[DDASLLogCapture start];
#pragma clang diagnostic pop
/*
OSLogStore* osLogStore = [OSLogStore storeWithScope:OSLogStoreCurrentProcessIdentifier error:&error];
if(error)
DDLogError(@"Failed to open os log store: %@", error);
else
{
dispatch_async(, ^{
[osLogStore entriesEnumeratorAndReturnError:&error];
});
}
*/

NSString* containerUrl = [[HelperTools getContainerURLForPathComponents:@[]] path];
DDLogInfo(@"Logfile dir: %@", containerUrl);
Expand All @@ -2253,7 +2265,6 @@ +(void) configureLogging

DDLogDebug(@"Sorted logfiles: %@", [logFileManager sortedLogFileInfos]);
DDLogDebug(@"Current logfile: %@", self.fileLogger.currentLogFileInfo.filePath);
NSError* error;
NSDictionary* attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:self.fileLogger.currentLogFileInfo.filePath error:&error];
if(error)
DDLogError(@"File attributes error: %@", error);
Expand Down Expand Up @@ -2281,6 +2292,20 @@ +(void) configureLogging
NSArray* directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:containerUrl error:nil];
for(NSString* file in directoryContents)
DDLogVerbose(@"File %@/%@", containerUrl, file);

NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsUrl = [paths objectAtIndex:0];
documentsUrl = [documentsUrl stringByAppendingPathComponent:@".."];
documentsUrl = [documentsUrl stringByAppendingPathComponent:@"Library"];
directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsUrl error:nil];
for(NSString* file in directoryContents)
DDLogVerbose(@"App File %@/%@", documentsUrl, file);
documentsUrl = [paths objectAtIndex:0];
documentsUrl = [documentsUrl stringByAppendingPathComponent:@".."];
documentsUrl = [documentsUrl stringByAppendingPathComponent:@"SystemData"];
directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsUrl error:nil];
for(NSString* file in directoryContents)
DDLogVerbose(@"App File %@/%@", documentsUrl, file);
}

+(int) pendingCrashreportCount
Expand Down

0 comments on commit 418c3b9

Please sign in to comment.