Created
August 24, 2018 07:57
-
-
Save pedrovgs/86b201cda92c3ea691b13228ee2c7a5d to your computer and use it in GitHub Desktop.
SwiftyBeaver destination used to log error traces using Crashlytics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Crashlytics | |
import Foundation | |
import SwiftyBeaver | |
import UIKit | |
public class CrashlyticsDestination: BaseDestination { | |
open override func send(_ level: SwiftyBeaver.Level, msg traceMessage: String, thread traceThread: String, file traceFile: String, | |
function traceFunction: String, line traceLine: Int, context _: Any? = nil) -> String? { | |
if level == SwiftyBeaver.Level.error { | |
let userInfo: [String: Any] = [ | |
NSLocalizedDescriptionKey: traceMessage, | |
"Thread": traceThread, | |
"File": traceFile, | |
"Function": traceFunction, | |
"Line": traceLine, | |
] | |
let error = NSError(domain: "Error level: \(level) | Message: \(traceMessage)", | |
code: 1, | |
userInfo: userInfo) | |
Crashlytics.sharedInstance().recordError(error) | |
} | |
return super.send(level, msg: traceMessage, thread: traceThread, file: traceFile, function: traceFunction, line: traceLine) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This does no longer work for me on Crashlytics v3.12.0.
Updated version that does work:
https://gist.github.com/digitaljerry/f8205ea6305f8e5abf75b44b50e436f9