Skip to content

Commit

Permalink
Merge pull request #20 from ibm-bluemix-mobile-services/development
Browse files Browse the repository at this point in the history
Released version 2.2.1
  • Loading branch information
mohlogan committed Nov 16, 2017
2 parents c36ccc3 + 8f0e685 commit e84bae4
Show file tree
Hide file tree
Showing 3 changed files with 352 additions and 8 deletions.
2 changes: 1 addition & 1 deletion BMSAnalytics.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = 'BMSAnalytics'
s.version = '2.2.0'
s.version = '2.2.1'
s.summary = 'The analytics component of the Swift client SDK for IBM Bluemix Mobile Services'
s.homepage = 'https://github.com/ibm-bluemix-mobile-services/bms-clientsdk-swift-analytics'
s.documentation_url = 'https://ibm-bluemix-mobile-services.github.io/API-docs/client-SDK/BMSAnalytics/Swift/index.html'
Expand Down
118 changes: 113 additions & 5 deletions Source/Logger/BMSLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,10 @@ public class BMSLogger: LoggerDelegate {

// This flag prevents infinite loops of uncaught exceptions
internal static var exceptionHasBeenCalled = false

internal static var signalHasBeenRaised = false
internal static func startCapturingUncaughtExceptions() {

NSSetUncaughtExceptionHandler { (uncaughtException: NSException) -> Void in

if (!BMSLogger.exceptionHasBeenCalled) {
// Persist a flag so that when the app starts back up, we can see if an exception occurred in the last session
BMSLogger.exceptionHasBeenCalled = true
Expand All @@ -258,9 +257,63 @@ public class BMSLogger: LoggerDelegate {
BMSLogger.existingUncaughtExceptionHandler?(uncaughtException)
}
}

BMSLogger.checkSignal()
}


internal static func checkSignal() {

signal(SIGSEGV) { signal in
BMSLogger.logOtherThanNSException(signalValue:"SIGSEGV", signalReason:String(cString:strsignal(signal)) )
}

signal(SIGABRT) { signal in
BMSLogger.logOtherThanNSException(signalValue:"SIGABRT", signalReason:String(cString:strsignal(signal)) )
}

signal(SIGILL) { signal in
BMSLogger.logOtherThanNSException(signalValue:"SIGILL", signalReason:String(cString:strsignal(signal)) )
}

signal(SIGFPE) { signal in
BMSLogger.logOtherThanNSException(signalValue:"SIGFPE", signalReason:String(cString:strsignal(signal)) )
}

signal(SIGBUS) { signal in
BMSLogger.logOtherThanNSException(signalValue:"SIGBUS", signalReason:String(cString:strsignal(signal)) )
}

signal(SIGPIPE) { signal in
BMSLogger.logOtherThanNSException(signalValue:"SIGPIPE", signalReason:String(cString:strsignal(signal)) )
}
}

internal static func logOtherThanNSException(signalValue:String, signalReason:String) {
if !BMSLogger.signalHasBeenRaised {
BMSLogger.signalHasBeenRaised = true
BMSLogger.exceptionHasBeenCalled = true
BMSLogger.log(trace: Thread.callStackSymbols, signalValue:signalValue, signalReason:signalReason )
BMSAnalytics.logSessionEnd()
abort()
}
}

internal static func log(trace crashTrace: [String], signalValue:String, signalReason:String) {

let message = "App Crash: Crashed with signal \(signalValue) (\(signalReason))"

let exceptionString = message
let stacktrace = crashTrace

var metadata: [String: Any] = [:]

metadata[Constants.Metadata.Analytics.stacktrace] = stacktrace
metadata[Constants.Metadata.Analytics.exceptionClass] = ""
metadata[Constants.Metadata.Analytics.exceptionMessage] = message

Logger.delegate?.logToFile(message: exceptionString, level: LogLevel.fatal, loggerName: Constants.Package.logger, calledFile: #file, calledFunction: #function, calledLineNumber: #line, additionalMetadata: metadata)
}

internal static func log(exception uncaughtException: NSException) {

var metadata: [String: Any] = [:]
Expand Down Expand Up @@ -851,11 +904,10 @@ public class BMSLogger: LoggerDelegate {

// This flag prevents infinite loops of uncaught exceptions
internal static var exceptionHasBeenCalled = false

internal static var signalHasBeenRaised = false
internal static func startCapturingUncaughtExceptions() {

NSSetUncaughtExceptionHandler { (uncaughtException: NSException) -> Void in

if (!BMSLogger.exceptionHasBeenCalled) {
// Persist a flag so that when the app starts back up, we can see if an exception occurred in the last session
BMSLogger.exceptionHasBeenCalled = true
Expand All @@ -866,9 +918,65 @@ public class BMSLogger: LoggerDelegate {
BMSLogger.existingUncaughtExceptionHandler?(uncaughtException)
}
}

BMSLogger.checkSignal()
}


internal static func checkSignal() {

signal(SIGSEGV) { signal in
BMSLogger.logOtherThanNSException(signalValue:"SIGSEGV", signalReason:String(String.fromCString(strsignal(signal))) )
}

signal(SIGABRT) { signal in
BMSLogger.logOtherThanNSException(signalValue:"SIGABRT", signalReason:String(String.fromCString(strsignal(signal))) )
}

signal(SIGILL) { signal in
BMSLogger.logOtherThanNSException(signalValue:"SIGILL", signalReason:String(String.fromCString(strsignal(signal))) )
}

signal(SIGFPE) { signal in
BMSLogger.logOtherThanNSException(signalValue:"SIGFPE", signalReason:String(String.fromCString(strsignal(signal))) )
}

signal(SIGBUS) { signal in
BMSLogger.logOtherThanNSException(signalValue:"SIGBUS", signalReason:String(String.fromCString(strsignal(signal))) )
}

signal(SIGPIPE) { signal in
BMSLogger.logOtherThanNSException(signalValue:"SIGPIPE", signalReason:String(String.fromCString(strsignal(signal))) )
}
}

internal static func logOtherThanNSException(signalValue signalValue:String, signalReason:String) {
if !BMSLogger.signalHasBeenRaised {
BMSLogger.signalHasBeenRaised = true
BMSLogger.exceptionHasBeenCalled = true
BMSLogger.log(trace: NSThread.callStackSymbols(), signalValue:signalValue, signalReason:signalReason)
BMSAnalytics.logSessionEnd()
abort()
}
}

internal static func log(trace crashTrace: [String], signalValue:String, signalReason:String) {

let message = "App Crash: Crashed with signal \(signalValue) (\(signalReason))"

let exceptionString = message
let stacktrace = crashTrace

var metadata: [String: AnyObject] = [:]

metadata[Constants.Metadata.Analytics.stacktrace] = stacktrace
metadata[Constants.Metadata.Analytics.exceptionClass] = ""
metadata[Constants.Metadata.Analytics.exceptionMessage] = message

Logger.delegate?.logToFile(message: exceptionString, level: LogLevel.fatal, loggerName: Constants.Package.logger, calledFile: #file, calledFunction: #function, calledLineNumber: #line, additionalMetadata: metadata)

}

internal static func log(exception uncaughtException: NSException) {

var metadata: [String: AnyObject] = [:]
Expand Down
Loading

0 comments on commit e84bae4

Please sign in to comment.