Skip to content

Instantly share code, notes, and snippets.

@pedrovgs
Created August 24, 2018 07:57
Show Gist options
  • Save pedrovgs/86b201cda92c3ea691b13228ee2c7a5d to your computer and use it in GitHub Desktop.
Save pedrovgs/86b201cda92c3ea691b13228ee2c7a5d to your computer and use it in GitHub Desktop.
SwiftyBeaver destination used to log error traces using Crashlytics
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)
}
}
@digitaljerry
Copy link

digitaljerry commented Apr 17, 2019

This does no longer work for me on Crashlytics v3.12.0.
Updated version that does work:
https://gist.github.com/digitaljerry/f8205ea6305f8e5abf75b44b50e436f9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment