Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: BibbiNetworkMonitor Legacy 코드 제거 #681

Merged
merged 6 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 14th-team5-iOS/App/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private let targets: [Target] = [
"CFBundleVersion": .string("1"),
"CFBuildVersion": .string("0"),
"CFBundleShortVersionString": .string("1.2.3"),
"UILaunchStoryboardName": .string("LaunchScreen.storyboard"),
"UILaunchStoryboardName": .string("LaunchScreen"),
"UISupportedInterfaceOrientations": .array([.string("UIInterfaceOrientationPortrait")]),
"UIUserInterfaceStyle": .string("Dark"),
"NSPhotoLibraryAddUsageDescription" : .string("프로필 사진, 피드 업로드를 위한 사진 촬영을 위해 Bibbi가 앨범에 접근할 수 있도록 허용해 주세요"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ extension BBNetworkDefaultLogger: BBNetworkEventMonitor {
httpLog.append("- HTTP BODY: \(httpBody)\n")
}

// TODO: - Logger로 로그 출력하기
print(httpLog + "\n--------------------------------------------------------\n")
BBLogger.logInfo(category: "Network", message: httpLog)
}

public func request(
Expand Down Expand Up @@ -84,8 +83,7 @@ extension BBNetworkDefaultLogger: BBNetworkEventMonitor {
httpLog.append("- STATUS CODE: \(statusCode)\n")
httpLog.append("- RESONSE DATA: \(responseDataString)\n")

// TODO: - Logger로 로그 출력하기
print(httpLog + "\n--------------------------------------------------------\n")
BBLogger.logInfo(category: "Network", message: httpLog)
}

public func request(
Expand Down
187 changes: 187 additions & 0 deletions 14th-team5-iOS/Core/Sources/Utils/Logger/BBLogger.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
//
// BBLogger.swift
// Core
//
// Created by 김도현 on 10/16/24.
//

import Foundation
import os

import RxSwift

/// LogLevel은 **OSLogType** 기준으로 정의를 했습니다.
/// 해당 **LogLevel** 을 통해서 BBLogger의 출력 메세지를 지정 할 수 있습니다.
private enum LogLevel {
/// 일반적인 정보를 조회할 때 사용하는 Type
/// ex) 네트워크 요청 시 Response 값 조회
case info
/// 코드 디버깅할 때 사용하는 Type
case debug
/// 경고 오류가 발생했을 때 사용하는 Type
case error
/// 크래시를 유발하는 오류 나타낼 때 사용하는 Type
case fault


var label: String {
switch self {
case .info: return "[INFO ⚪]"
case .debug: return "[DEBUG 🟢]"
case .error: return "[ERROR 🟠]"
case .fault: return "[FAULT 🔴]"
}
}
}


public struct BBLogger {
/// 일반적인 정보를 조회할때 사용하는 메서드 입니다.
/// - Parameters:
/// - function: logInfo 메서드를 호출한 함수명
/// - fileName: logInfo 메서드를 호출한 파일명
/// - category: 로그의 카테고리 예) "Network", "UI", "UseCase",
/// - message: 로그 메세지
public static func logInfo(
function: String = #function,
fileName: String = #file,
category: String = "",
message: String = ""
) {
guard let bundleId = Bundle.main.bundleIdentifier else {
fatalError("Bundle ID value not found")
}

let infotMessage = createLoggerMessage(
level: LogLevel.info,
message: message,
function: function,
fileName: fileName
)

Logger(subsystem: bundleId, category: category)
.info("\(infotMessage)")
}

/// 코드 디버깅할때 사용하는 메서드 입니다..
/// - Parameters:
/// - function: logInfo 메서드를 호출한 함수명
/// - fileName: logInfo 메서드를 호출한 파일명
/// - category: 로그의 카테고리 예) "Network", "UI", "UseCase",
/// - message: 로그 메세지
public static func logDebug(
function: String = #function,
fileName: String = #file,
category: String = "",
message: String = ""
) {

guard let bundleId = Bundle.main.bundleIdentifier else {
fatalError("Bundle ID value not found")
}

let debugMessage = createLoggerMessage(
level: LogLevel.debug,
message: message,
function: function,
fileName: fileName
)

Logger(subsystem: bundleId, category: category)
.debug("\(debugMessage)")

}

/// 경고 오류를 기록 및 추적할 때 사용하는 메서드입니다.
/// - Parameters:
/// - function: logInfo 메서드를 호출한 함수명
/// - fileName: logInfo 메서드를 호출한 파일명
/// - category: 로그의 카테고리 예) "Network", "UI", "UseCase",
/// - message: 로그 메세지
public static func logError(
function: String = #function,
fileName: String = #file,
category: String = "",
message: String = ""
) {
guard let bundleId = Bundle.main.bundleIdentifier else {
fatalError("Bundle ID value not found")
}

let errorMessage = createLoggerMessage(
level: LogLevel.error,
message: message,
function: function,
fileName: fileName
)

Logger(subsystem: bundleId, category: category)
.error("\(errorMessage)")
}

/// 크래시 오류를 추적 및 기록할 때 사용하는 메서드입니다.
/// - Parameters:
/// - function: logInfo 메서드를 호출한 함수명
/// - fileName: logInfo 메서드를 호출한 파일명
/// - category: 로그의 카테고리 예) "Network", "UI", "UseCase",
/// - message: 로그 메세지
public static func logFault(
function: String = #function,
fileName: String = #file,
category: String = "",
message: String = ""
) {
guard let bundleId = Bundle.main.bundleIdentifier else {
fatalError("Bundle ID value not found")
}

let faultMessage = createLoggerMessage(
level: LogLevel.fault,
message: message,
function: function,
fileName: fileName
)

Logger(subsystem: bundleId, category: category)
.fault("\(faultMessage)")
}
}


extension BBLogger {

/// 로그 메서드 내부 출력 구문을 생성하기 위한 메서드입니다.
/// - Parameters:
/// - level: LogLevel Type
/// - message: 로그 메세지
/// - function: logInfo 메서드를 호출한 함수명
/// - fileName: logInfo 메서드를 호출한 파일명
private static func createLoggerMessage(
level: LogLevel,
message: String,
function: String = #function,
fileName: String = #file
) -> String {

let timestamp: String = "🕖 \(Date().toFormatString(with: .ahhmmss))"
let functionName: String = "#️⃣ \(function)"
let filename: String = URL(fileURLWithPath: fileName).lastPathComponent
let message: String = "\n\(message)"

return Array(arrayLiteral: level.label, timestamp, filename, functionName, message).joined(separator: "|")
}
}



extension ObservableType {
/// RxSwift에서 제공되는. debug 연산자와 동일하게 element를 로깅 하는 연산자입니다.
/// 해당 연산자를 통해서 BBLogger를 사용하여 로깅을 할 수 있습니다.
/// - Parameters:
/// - category: 로그의 카테고리 예) "Network", "UI", "UseCase",
public func log(_ category: String) -> Observable<Element> {
return self.do(onNext: { element in
BBLogger.logDebug(category: category, message: "\(element)")
})
}
}
2 changes: 1 addition & 1 deletion 14th-team5-iOS/Data/Sources/Trash/APIWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class APIWorker: NSObject {

var id: String = "APIWorker"
private static let session: Session = {
let networkMonitor: BibbiNetworkMonitor = BibbiNetworkMonitor()
let networkMonitor: BBNetworkEventMonitor = BBNetworkDefaultLogger()
let networkConfiguration: URLSessionConfiguration = AF.session.configuration
let networkInterceptor: RequestInterceptor = NetworkInterceptor()
let networkSession: Session = Session(
Expand Down
39 changes: 0 additions & 39 deletions 14th-team5-iOS/Data/Sources/Trash/BibbiNetworkMonitor.swift

This file was deleted.

2 changes: 1 addition & 1 deletion Tuist/ProjectDescriptionHelpers/Modular+Templates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ extension Target {
case .App:
return .target(
name: layer.rawValue,
destinations: .iOS,
destinations: [.iPhone],
product: factory.products.isApp ? .app : .staticFramework,
bundleId: factory.bundleId.lowercased(),
deploymentTargets: factory.deploymentTargets,
Expand Down
2 changes: 1 addition & 1 deletion Tuist/ProjectDescriptionHelpers/Project+Templates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extension Project {
settings: .settings(
base: [
"OTHER_LDFLAGS": ["-ObjC"],
"MARKETING_VERSION": "1.0",
"MARKETING_VERSION": "1.2.3",
"CURRENT_PROJECT_VERSION": "1",
"VERSIONING_SYSTEM": "apple-generic"
],
Expand Down
16 changes: 12 additions & 4 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ platform :ios do


lane :github_action_stg_upload_testflight do |options|
app_store_connect_api_key(
api_key = app_store_connect_api_key(
key_id: "#{APP_STORE_CONNECT_API_KEY_KEY_ID}",
issuer_id: "#{APP_STORE_CONNECT_API_KEY_ISSUER_ID}",
key_content: "#{APP_STORE_CONNECT_API_KEY_KEY}",
Expand All @@ -62,7 +62,11 @@ platform :ios do
generate_apple_certs: false
)

new_build_number = latest_testflight_build_number() + 1
build_num = app_store_build_number(
api_key: api_key
)

new_build_number = build_num + 1


increment_build_number(
Expand Down Expand Up @@ -125,7 +129,7 @@ platform :ios do


lane :github_action_prd_upload_testflight do |options|
app_store_connect_api_key(
api_key = app_store_connect_api_key(
key_id: "#{APP_STORE_CONNECT_API_KEY_KEY_ID}",
issuer_id: "#{APP_STORE_CONNECT_API_KEY_ISSUER_ID}",
key_content: "#{APP_STORE_CONNECT_API_KEY_KEY}",
Expand All @@ -144,7 +148,11 @@ platform :ios do
generate_apple_certs: false
)

new_build_number = latest_testflight_build_number() + 1
build_num = app_store_build_number(
api_key: api_key
)

new_build_number = build_num + 1


increment_build_number(
Expand Down
Loading