Skip to content

Commit

Permalink
[Setting/#303] assertion error 슬랙 로깅 연결 #304
Browse files Browse the repository at this point in the history
  • Loading branch information
JongHoooon authored Oct 15, 2024
1 parent 26ae24d commit e280a64
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
75 changes: 74 additions & 1 deletion Projects/Core/Logger/Interface/Sources/Log.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by 임현규 on 7/23/24.
//

import Foundation
import UIKit
import OSLog

public enum Log {
Expand Down Expand Up @@ -132,6 +132,79 @@ public extension Log {
let logMessage = "\(message ?? "")"
log(message: logMessage, level: level, fileName: fileName, line: line, funcName: funcName)
assertionFailure(logMessage)
#if !DEBUG
Task {
guard let url = URL(string: Bundle.main.infoDictionary?["SLACK_WEBHOOK_URL"] as? String ?? "")
else {
return
}
guard let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String,
let buildNumber = Bundle.main.infoDictionary?["CFBundleVersion"] as? String
else {
return
}
async let device = UIDevice.current
let systemVersion = await device.systemVersion
let deviceName = await UIDevice.current.name

let errorLogJsonObject: [String: Any] = [
"pretext": "iOS Error Occured🔥",
"color": "#36a64f",
"fields": [
[
"title": "Message",
"value": "\(message ?? "no message")",
"short": true
],
[
"title": "File Name",
"value": "\(fileName)",
"short": true
],
[
"title": "Function Name",
"value": "\(funcName)",
"short": true
],
[
"title": "Line",
"value": "\(line)",
"short": true
],
[
"title": "Version",
"value": "\(appVersion)",
"short": true
],
[
"title": "Build Number",
"value": "\(buildNumber)",
"short": true
],
[
"title": "Device Name",
"value": "\(deviceName)",
"short": true
],
[
"title": "iOS Version",
"value": "\(systemVersion)",
"short": true
]
]
]
do {
let errorLogJsonData = try JSONSerialization.data(withJSONObject: errorLogJsonObject)
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = errorLogJsonData
_ = try await URLSession.shared.data(for: request)
} catch {
Log.debug(error)
}
}
#endif
}

static func fatal(message: Any?, level: Level = .fault, fileName: String = #fileID, line: Int = #line, funcName: StaticString = #function) {
Expand Down
1 change: 1 addition & 0 deletions Tuist/ProjectDescriptionHelpers/InfoPlist+Templates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public extension InfoPlist {
"APP_STORE_URL": "$(APP_STORE_URL)",
"APP_LOOK_UP_URL": "$(APP_LOOK_UP_URL)",
"KAKAO_CHANNEL_TALK_URL": "$(KAKAO_CHANNEL_TALK_URL)",
"SLACK_WEBHOOK_URL": "$(SLACK_WEBHOOK_URL)",
"LSApplicationQueriesSchemes": ["kakaokompassauth", "kakaotalk"],
"CFBundleURLTypes": [
[
Expand Down

0 comments on commit e280a64

Please sign in to comment.