Skip to content

Instantly share code, notes, and snippets.

@emirhankolver
Created December 22, 2025 10:19
Show Gist options
  • Select an option

  • Save emirhankolver/8cce320dbd11f83b2d864c72446538c7 to your computer and use it in GitHub Desktop.

Select an option

Save emirhankolver/8cce320dbd11f83b2d864c72446538c7 to your computer and use it in GitHub Desktop.
SwiftyBeaver → Firebase Crashlytics Logging Destination (Swift)
//
// 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
)
}
}
@emirhankolver
Copy link
Author

Here's example log report at firebase crashlytics:

The result of my old destination is first report and current destination is second report.

image

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