Skip to content

Commit

Permalink
feat: BibbiNetworkMonitor Legacy 코드 제거
Browse files Browse the repository at this point in the history
- BBNetworkEventMonitor BBLogger 출력구문 추가
- BBLogger 내부 Logger Method 추가
- BBLogger log ObservableType 추가
  • Loading branch information
Do-hyun-Kim committed Oct 16, 2024
1 parent 1f53d82 commit 757b27a
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 44 deletions.
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
149 changes: 149 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,149 @@
//
// BBLogger.swift
// Core
//
// Created by 김도현 on 10/16/24.
//

import Foundation
import os

import RxSwift


private enum LogLevel {
case info
case debug
case error
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 {
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)")
}


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)")

}


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 errortMessage = createLoggerMessage(
level: LogLevel.error,
message: message,
function: function,
fileName: fileName
)

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

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 {

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 {
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.

0 comments on commit 757b27a

Please sign in to comment.