Skip to content

Commit

Permalink
Improve crash logging
Browse files Browse the repository at this point in the history
  • Loading branch information
tmolitor-stud-tu committed Jan 4, 2025
1 parent 6aedd4c commit e32cbe3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
9 changes: 4 additions & 5 deletions Monal/Classes/DebugView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,27 +137,26 @@ struct CrashTestingView: View {
Group {
Button("Try to call unknown handler method") {
DispatchQueue.global(qos: .default).async(execute: {
HelperTools.flushLogs(withTimeout: 0.100)
let handler = MLHandler(delegate: self, handlerName: "IDontKnowThis", andBoundArguments: [:])
handler.call(withArguments: nil)
})
}
Button("Bad Access Crash") {
HelperTools.flushLogs(withTimeout: 0.100)
let delegate: AnyClass? = NSClassFromString("MonalAppDelegate")
print(delegate.unsafelyUnwrapped.audiovisualTypes())

}
Button("Assertion Crash") {
Button("MLAssert Crash") {
HelperTools.flushLogs(withTimeout: 0.100)
MLAssert(false, "MLAssert_example")
}
Button("Assertion Crash") {
assert(false)
}
Button("Fatal Error Crash") {
HelperTools.flushLogs(withTimeout: 0.100)
fatalError("fatalError_example")
}
Button("Nil Crash") {
HelperTools.flushLogs(withTimeout: 0.100)
let crasher:Int? = nil
print(crasher!)
}
Expand Down
20 changes: 13 additions & 7 deletions Monal/Classes/HelperTools.m
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,7 @@ void logException(NSException* exception)
NSString* prefix = @"CRASH";
#endif
//log error and flush all logs
[DDLog flushLog];
DDLogError(@"*****************\n%@(%@): %@\nUserInfo: %@\nStack Trace: %@", prefix, [exception name], [exception reason], [exception userInfo], [exception callStackSymbols]);
[DDLog flushLog];
[HelperTools flushLogsWithTimeout:0.250];
}

Expand Down Expand Up @@ -2232,6 +2230,8 @@ +(void) configureXcodeLogging

+(void) configureLogging
{
NSError* error;

//network logger (start as early as possible)
MLUDPLogger* udpLogger = [MLUDPLogger new];
[DDLog addLogger:udpLogger];
Expand All @@ -2245,10 +2245,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 @@ -2265,7 +2272,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

0 comments on commit e32cbe3

Please sign in to comment.