diff --git a/Cherrish-iOS/Cherrish-iOS.xcodeproj/project.pbxproj b/Cherrish-iOS/Cherrish-iOS.xcodeproj/project.pbxproj index 57d7584a..262bbef2 100644 --- a/Cherrish-iOS/Cherrish-iOS.xcodeproj/project.pbxproj +++ b/Cherrish-iOS/Cherrish-iOS.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXFileReference section */ + 5126F89E2F0E9AF000E67E33 /* OSLog.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OSLog.framework; path = System/Library/Frameworks/OSLog.framework; sourceTree = SDKROOT; }; 51B5D3182F0514390090B8B4 /* Cherrish-iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Cherrish-iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -42,10 +43,19 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 5126F89D2F0E9AF000E67E33 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 5126F89E2F0E9AF000E67E33 /* OSLog.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; 51B5D30F2F0514390090B8B4 = { isa = PBXGroup; children = ( 51B5D31A2F0514390090B8B4 /* Cherrish-iOS */, + 5126F89D2F0E9AF000E67E33 /* Frameworks */, 51B5D3192F0514390090B8B4 /* Products */, ); sourceTree = ""; @@ -262,10 +272,12 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; - CODE_SIGN_STYLE = Automatic; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = ""; - DEVELOPMENT_TEAM = CG37U6CMKP; + DEVELOPMENT_TEAM = ""; + "DEVELOPMENT_TEAM[sdk=iphoneos*]" = CG37U6CMKP; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Cherrish-iOS/Info.plist"; @@ -282,6 +294,8 @@ MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = "com.nayeon.Cherrish-iOS"; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; + "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "cherrish-development"; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; @@ -293,10 +307,12 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; - CODE_SIGN_STYLE = Automatic; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; + CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = ""; - DEVELOPMENT_TEAM = CG37U6CMKP; + DEVELOPMENT_TEAM = ""; + "DEVELOPMENT_TEAM[sdk=iphoneos*]" = CG37U6CMKP; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Cherrish-iOS/Info.plist"; @@ -313,6 +329,8 @@ MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = "com.nayeon.Cherrish-iOS"; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; + "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "cherrish-distribution"; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; diff --git a/Cherrish-iOS/Cherrish-iOS/Core/CherrishError.swift b/Cherrish-iOS/Cherrish-iOS/Core/CherrishError.swift new file mode 100644 index 00000000..4ee84b35 --- /dev/null +++ b/Cherrish-iOS/Cherrish-iOS/Core/CherrishError.swift @@ -0,0 +1,43 @@ +// +// CherrishError.swift +// Cherrish-iOS +// +// Created by 이나연 on 1/8/26. +// + +import Foundation + +enum CherrishError: Error, LocalizedError, Equatable { + case DIFailedError + case decodingError + case URLError + case networkRequestFailed + case networkConnect + case networkError(code: Int, message: String) + case noData + case unknownError + case encodingError + + var errorDescription: String? { + switch self { + case .DIFailedError: + return "의존성 주입 실패" + case .decodingError: + return "디코딩 실패" + case .URLError: + return "URL 변환 실패" + case .networkRequestFailed: + return "네트워크 요청 실패" + case .networkConnect: + return "네트워크 연결 에러" + case .networkError(let code, let message): + return "\(code): \(message)" + case .noData: + return "데이터 없음" + case .encodingError: + return "인코딩 실패" + case .unknownError: + return "알 수 없는 오류" + } + } +} diff --git a/Cherrish-iOS/Cherrish-iOS/Core/CherrishLogger.swift b/Cherrish-iOS/Cherrish-iOS/Core/CherrishLogger.swift index 91f7ce4a..6c2cea27 100644 --- a/Cherrish-iOS/Cherrish-iOS/Core/CherrishLogger.swift +++ b/Cherrish-iOS/Cherrish-iOS/Core/CherrishLogger.swift @@ -5,3 +5,150 @@ // Created by 이나연 on 12/31/25. // +import OSLog + +extension OSLog { + static let subsystem = Bundle.main.bundleIdentifier! + static let network = OSLog(subsystem: subsystem, category: "Network") + static let debug = OSLog(subsystem: subsystem, category: "Debug") + static let data = OSLog(subsystem: subsystem, category: "Data") + static let error = OSLog(subsystem: subsystem, category: "Error") +} + +enum LogType { + case network + case debug + case data + case error(error: Error) + + var category: String { + switch self { + case .network: + return "Network" + case .debug: + return "Debug" + case .data: + return "Data" + case .error: + return "Error" + } + } + + var osLog: OSLog { + switch self { + case .network: + return OSLog.network + case .debug: + return OSLog.debug + case .data: + return OSLog.data + case .error: + return OSLog.error + } + } + + var osLogType: OSLogType { + switch self { + case .network, .data: + return .default + case .debug: + return .debug + case .error: + return .error + } + } + + var shouldShowLogInRelease: Bool { + switch self { + case .error: + true + default: + false + } + } +} + +struct CherrishLogger { + private static var isDebugMode: Bool { + #if DEBUG + return true + #else + return false + #endif + } + + private static func shouldShowLog(type: LogType) -> Bool { + if isDebugMode { return true } + + return type.shouldShowLogInRelease + } + + private static let dateFormatter: DateFormatter = { + let formatter = DateFormatter() + formatter.dateFormat = "yyyy/MM/dd HH:mm:ss" + formatter.locale = Locale(identifier: "en_US_POSIX") + return formatter + }() + + private static var timestamp: String { + dateFormatter.string(from: Date()) + } + + static private func log( + type: LogType, + message: Any, + file: String, + function: String + + ) { + guard shouldShowLog(type: type) else { return } + + let logger = Logger(subsystem: OSLog.subsystem, category: type.category) + let logMessage = "\(message)" + let fileName = (file as NSString).lastPathComponent + + switch type { + case .network: + logger.log("[🛜 Network] [Date: \(timestamp)] [\(fileName) -> \(function)]: \(logMessage)") + case .debug: + logger.debug("[🐛 Debug] [Date: \(timestamp)] [\(fileName) -> \(function)]: \(logMessage)") + case .data: + logger.info("[📊 Data] [Date: \(timestamp)] [\(fileName) -> \(function)]: \(logMessage)") + case .error(let error): + logger.error("[❌ Error] [Date: \(timestamp)] [\(fileName) -> \(function)]: \(error.localizedDescription)") + + } + } + + static func network( + _ message: Any, + file: String = #file, + function: String = #function + ) { + log(type: .network, message: message, file: file, function: function) + } + + static func debug( + _ message: Any, + file: String = #file, + function: String = #function + ) { + log(type: .debug, message: message, file: file, function: function) + } + + static func data( + _ message: Any, + file: String = #file, + function: String = #function + ) { + log(type: .data, message: message, file: file, function: function) + } + + static func error( + _ error: Error, + file: String = #file, + function: String = #function + ) { + log(type: .error(error: error), message: "", file: file, function: function) + } +} diff --git a/Cherrish-iOS/Cherrish-iOS/Presentation/Feature/TestViewModel.swift b/Cherrish-iOS/Cherrish-iOS/Presentation/Feature/TestViewModel.swift index c3d4bd43..5222e0cf 100644 --- a/Cherrish-iOS/Cherrish-iOS/Presentation/Feature/TestViewModel.swift +++ b/Cherrish-iOS/Cherrish-iOS/Presentation/Feature/TestViewModel.swift @@ -18,6 +18,6 @@ final class TestViewModel: ObservableObject { func test() { testUseCase.execute() text = "버튼 터치했음!" - print("view model execute") + CherrishLogger.debug("로거 테스트") } }