Skip to content

Commit e32cbe3

Browse files
Improve crash logging
1 parent 6aedd4c commit e32cbe3

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

Monal/Classes/DebugView.swift

+4-5
Original file line numberDiff line numberDiff line change
@@ -137,27 +137,26 @@ 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)
141140
let handler = MLHandler(delegate: self, handlerName: "IDontKnowThis", andBoundArguments: [:])
142141
handler.call(withArguments: nil)
143142
})
144143
}
145144
Button("Bad Access Crash") {
146-
HelperTools.flushLogs(withTimeout: 0.100)
147145
let delegate: AnyClass? = NSClassFromString("MonalAppDelegate")
148146
print(delegate.unsafelyUnwrapped.audiovisualTypes())
149147

150148
}
151-
Button("Assertion Crash") {
149+
Button("MLAssert Crash") {
152150
HelperTools.flushLogs(withTimeout: 0.100)
151+
MLAssert(false, "MLAssert_example")
152+
}
153+
Button("Assertion Crash") {
153154
assert(false)
154155
}
155156
Button("Fatal Error Crash") {
156-
HelperTools.flushLogs(withTimeout: 0.100)
157157
fatalError("fatalError_example")
158158
}
159159
Button("Nil Crash") {
160-
HelperTools.flushLogs(withTimeout: 0.100)
161160
let crasher:Int? = nil
162161
print(crasher!)
163162
}

Monal/Classes/HelperTools.m

+13-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

@@ -2232,6 +2230,8 @@ +(void) configureXcodeLogging
22322230

22332231
+(void) configureLogging
22342232
{
2233+
NSError* error;
2234+
22352235
//network logger (start as early as possible)
22362236
MLUDPLogger* udpLogger = [MLUDPLogger new];
22372237
[DDLog addLogger:udpLogger];
@@ -2245,10 +2245,17 @@ +(void) configureLogging
22452245
printf("stdout redirection complete...");
22462246

22472247
//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
2248+
/*
2249+
OSLogStore* osLogStore = [OSLogStore storeWithScope:OSLogStoreCurrentProcessIdentifier error:&error];
2250+
if(error)
2251+
DDLogError(@"Failed to open os log store: %@", error);
2252+
else
2253+
{
2254+
dispatch_async(, ^{
2255+
[osLogStore entriesEnumeratorAndReturnError:&error];
2256+
});
2257+
}
2258+
*/
22522259

22532260
NSString* containerUrl = [[HelperTools getContainerURLForPathComponents:@[]] path];
22542261
DDLogInfo(@"Logfile dir: %@", containerUrl);
@@ -2265,7 +2272,6 @@ +(void) configureLogging
22652272

22662273
DDLogDebug(@"Sorted logfiles: %@", [logFileManager sortedLogFileInfos]);
22672274
DDLogDebug(@"Current logfile: %@", self.fileLogger.currentLogFileInfo.filePath);
2268-
NSError* error;
22692275
NSDictionary* attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:self.fileLogger.currentLogFileInfo.filePath error:&error];
22702276
if(error)
22712277
DDLogError(@"File attributes error: %@", error);

0 commit comments

Comments
 (0)