-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: BibbiNetworkMonitor Legacy 코드 제거
- BBNetworkEventMonitor BBLogger 출력구문 추가 - BBLogger 내부 Logger Method 추가 - BBLogger log ObservableType 추가
- Loading branch information
1 parent
1f53d82
commit 757b27a
Showing
4 changed files
with
152 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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
149 changes: 149 additions & 0 deletions
149
14th-team5-iOS/Core/Sources/Utils/Logger/BBLogger.swift
This file contains 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
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)") | ||
}) | ||
} | ||
} |
This file contains 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
39 changes: 0 additions & 39 deletions
39
14th-team5-iOS/Data/Sources/Trash/BibbiNetworkMonitor.swift
This file was deleted.
Oops, something went wrong.