Created
December 22, 2025 10:19
-
-
Save emirhankolver/8cce320dbd11f83b2d864c72446538c7 to your computer and use it in GitHub Desktop.
SwiftyBeaver → Firebase Crashlytics Logging Destination (Swift)
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
| // | |
| // CrashlyticsDestination.swift | |
| // ExampleProject | |
| // | |
| // Created by emirhankolver on 14.11.2025. | |
| // | |
| import FirebaseCrashlytics | |
| import SwiftyBeaver | |
| nonisolated class CrashlyticsDestination: BaseDestination { | |
| override func send( | |
| _ level: SwiftyBeaver.Level, | |
| msg: String, | |
| thread: String, | |
| file: String, | |
| function: String, | |
| line: Int, | |
| context: Any? = nil | |
| ) -> String? { | |
| // The file parameter is the entire path to the file and we are only interested | |
| // in the filename. Because we only want the file name, we split the string on | |
| // path components and then grab the last component (the filename). | |
| var filename = file | |
| if let actualFilename = file.split(separator: "/").last { | |
| filename = String(actualFilename) | |
| } | |
| switch level { | |
| case .error, .warning: | |
| let domain = "\(filename):\(line) \(function)" | |
| // capture current call stack | |
| let error = NSError( | |
| domain: domain, | |
| code: 0, | |
| userInfo: [ | |
| NSLocalizedDescriptionKey: msg, | |
| "file": file, | |
| "function": function, | |
| "line": line, | |
| "stack": thread, | |
| ] | |
| ) | |
| Crashlytics.crashlytics().record(error: error) | |
| break | |
| case .info: | |
| Crashlytics.crashlytics().log(msg) | |
| break | |
| default: | |
| break | |
| } | |
| return super.send( | |
| level, | |
| msg: msg, | |
| thread: thread, | |
| file: file, | |
| function: function, | |
| line: line | |
| ) | |
| } | |
| } | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's example log report at firebase crashlytics: