Skip to content

Commit bae7dea

Browse files
DEBUG: file logging
1 parent 6aedd4c commit bae7dea

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

Monal/Classes/DebugView.swift

+12-5
Original file line numberDiff line numberDiff line change
@@ -137,27 +137,34 @@ struct CrashTestingView: View {
137137
Group {
138138
Button("Try to call unknown handler method") {
139139
DispatchQueue.global(qos: .default).async(execute: {
140-
HelperTools.flushLogs(withTimeout: 0.100)
140+
//HelperTools.flushLogs(withTimeout: 0.100)
141141
let handler = MLHandler(delegate: self, handlerName: "IDontKnowThis", andBoundArguments: [:])
142142
handler.call(withArguments: nil)
143143
})
144144
}
145145
Button("Bad Access Crash") {
146-
HelperTools.flushLogs(withTimeout: 0.100)
146+
//HelperTools.flushLogs(withTimeout: 0.100)
147147
let delegate: AnyClass? = NSClassFromString("MonalAppDelegate")
148148
print(delegate.unsafelyUnwrapped.audiovisualTypes())
149149

150150
}
151+
Button("MLAssert Crash") {
152+
//HelperTools.flushLogs(withTimeout: 0.100)
153+
MLAssert(false, "MLAssert_example1")
154+
}
155+
Button("MLAssert Crash without flush") {
156+
MLAssert(false, "MLAssert_example2")
157+
}
151158
Button("Assertion Crash") {
152-
HelperTools.flushLogs(withTimeout: 0.100)
159+
//HelperTools.flushLogs(withTimeout: 0.100)
153160
assert(false)
154161
}
155162
Button("Fatal Error Crash") {
156-
HelperTools.flushLogs(withTimeout: 0.100)
163+
//HelperTools.flushLogs(withTimeout: 0.100)
157164
fatalError("fatalError_example")
158165
}
159166
Button("Nil Crash") {
160-
HelperTools.flushLogs(withTimeout: 0.100)
167+
//HelperTools.flushLogs(withTimeout: 0.100)
161168
let crasher:Int? = nil
162169
print(crasher!)
163170
}

Monal/Classes/HelperTools.m

+28-7
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,7 @@ void logException(NSException* exception)
277277
NSString* prefix = @"CRASH";
278278
#endif
279279
//log error and flush all logs
280-
[DDLog flushLog];
281280
DDLogError(@"*****************\n%@(%@): %@\nUserInfo: %@\nStack Trace: %@", prefix, [exception name], [exception reason], [exception userInfo], [exception callStackSymbols]);
282-
[DDLog flushLog];
283281
[HelperTools flushLogsWithTimeout:0.250];
284282
}
285283

@@ -598,6 +596,7 @@ +(void) initSystem
598596
if(enableDefaultLogAndCrashFramework)
599597
{
600598
[self configureLogging];
599+
[self installExceptionHandler];
601600
//don't install KSCrash if the debugger is active
602601
if(!isDebugerActive())
603602
[self installCrashHandler];
@@ -2232,6 +2231,8 @@ +(void) configureXcodeLogging
22322231

22332232
+(void) configureLogging
22342233
{
2234+
NSError* error;
2235+
22352236
//network logger (start as early as possible)
22362237
MLUDPLogger* udpLogger = [MLUDPLogger new];
22372238
[DDLog addLogger:udpLogger];
@@ -2245,10 +2246,17 @@ +(void) configureLogging
22452246
printf("stdout redirection complete...");
22462247

22472248
//redirect apple system logs, too
2248-
#pragma clang diagnostic push
2249-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
2250-
[DDASLLogCapture start];
2251-
#pragma clang diagnostic pop
2249+
/*
2250+
OSLogStore* osLogStore = [OSLogStore storeWithScope:OSLogStoreCurrentProcessIdentifier error:&error];
2251+
if(error)
2252+
DDLogError(@"Failed to open os log store: %@", error);
2253+
else
2254+
{
2255+
dispatch_async(, ^{
2256+
[osLogStore entriesEnumeratorAndReturnError:&error];
2257+
});
2258+
}
2259+
*/
22522260

22532261
NSString* containerUrl = [[HelperTools getContainerURLForPathComponents:@[]] path];
22542262
DDLogInfo(@"Logfile dir: %@", containerUrl);
@@ -2265,7 +2273,6 @@ +(void) configureLogging
22652273

22662274
DDLogDebug(@"Sorted logfiles: %@", [logFileManager sortedLogFileInfos]);
22672275
DDLogDebug(@"Current logfile: %@", self.fileLogger.currentLogFileInfo.filePath);
2268-
NSError* error;
22692276
NSDictionary* attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:self.fileLogger.currentLogFileInfo.filePath error:&error];
22702277
if(error)
22712278
DDLogError(@"File attributes error: %@", error);
@@ -2293,6 +2300,20 @@ +(void) configureLogging
22932300
NSArray* directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:containerUrl error:nil];
22942301
for(NSString* file in directoryContents)
22952302
DDLogVerbose(@"File %@/%@", containerUrl, file);
2303+
2304+
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
2305+
NSString* documentsUrl = [paths objectAtIndex:0];
2306+
documentsUrl = [documentsUrl stringByAppendingPathComponent:@".."];
2307+
documentsUrl = [documentsUrl stringByAppendingPathComponent:@"Library"];
2308+
directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsUrl error:nil];
2309+
for(NSString* file in directoryContents)
2310+
DDLogVerbose(@"App File %@/%@", documentsUrl, file);
2311+
documentsUrl = [paths objectAtIndex:0];
2312+
documentsUrl = [documentsUrl stringByAppendingPathComponent:@".."];
2313+
documentsUrl = [documentsUrl stringByAppendingPathComponent:@"SystemData"];
2314+
directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsUrl error:nil];
2315+
for(NSString* file in directoryContents)
2316+
DDLogVerbose(@"App File %@/%@", documentsUrl, file);
22962317
}
22972318

22982319
+(int) pendingCrashreportCount

0 commit comments

Comments
 (0)