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 4, 2025
1 parent 6aedd4c commit bae7dea
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
17 changes: 12 additions & 5 deletions Monal/Classes/DebugView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,27 +137,34 @@ struct CrashTestingView: View {
Group {
Button("Try to call unknown handler method") {
DispatchQueue.global(qos: .default).async(execute: {
HelperTools.flushLogs(withTimeout: 0.100)
//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)
//HelperTools.flushLogs(withTimeout: 0.100)
let delegate: AnyClass? = NSClassFromString("MonalAppDelegate")
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)
//HelperTools.flushLogs(withTimeout: 0.100)
assert(false)
}
Button("Fatal Error Crash") {
HelperTools.flushLogs(withTimeout: 0.100)
//HelperTools.flushLogs(withTimeout: 0.100)
fatalError("fatalError_example")
}
Button("Nil Crash") {
HelperTools.flushLogs(withTimeout: 0.100)
//HelperTools.flushLogs(withTimeout: 0.100)
let crasher:Int? = nil
print(crasher!)
}
Expand Down
35 changes: 28 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 @@ -598,6 +596,7 @@ +(void) initSystem
if(enableDefaultLogAndCrashFramework)
{
[self configureLogging];
[self installExceptionHandler];
//don't install KSCrash if the debugger is active
if(!isDebugerActive())
[self installCrashHandler];
Expand Down Expand Up @@ -2232,6 +2231,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 +2246,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 +2273,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 @@ -2293,6 +2300,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 bae7dea

Please sign in to comment.