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 5eff626 commit 3c4d40b
Showing 1 changed file with 37 additions and 13 deletions.
50 changes: 37 additions & 13 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 @@ -599,10 +601,10 @@ +(void) initSystem
{
[self configureLogging];
//don't install KSCrash if the debugger is active
if(!isDebugerActive())
//if(!isDebugerActive())
[self installCrashHandler];
else
DDLogWarn(@"Not installing crash handler: debugger is active!");
// else
// DDLogWarn(@"Not installing crash handler: debugger is active!");
[self installExceptionHandler];
}
else
Expand Down Expand Up @@ -2220,6 +2222,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 +2237,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 +2264,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 +2291,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 3c4d40b

Please sign in to comment.