-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from tukcomCD2024/DeviOS
Devi os
- Loading branch information
Showing
24 changed files
with
728 additions
and
309 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
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
12 changes: 0 additions & 12 deletions
12
iOS/RollTheDice/RollTheDice/Source/Domain/RollTheDiceAPI/RollTheDiceAPI.swift
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
iOS/RollTheDice/RollTheDice/Source/Domain/ScoopAPI/ScoopAPI.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,12 @@ | ||
// | ||
// RollTheDiceAPI.swift | ||
// RollTheDice | ||
// | ||
// Created by Subeen on 3/21/24. | ||
// | ||
|
||
import Foundation | ||
|
||
enum ScoopAPI { | ||
static let baseURL = "http://ec2-13-124-191-244.ap-northeast-2.compute.amazonaws.com:8080" | ||
} |
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
43 changes: 43 additions & 0 deletions
43
iOS/RollTheDice/RollTheDice/Source/Domain/Service/Log/Extension+Log.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,43 @@ | ||
// | ||
// Extension+Log.swift | ||
// RollTheDice | ||
// | ||
// Created by Subeen on 5/14/24. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension Log { | ||
//MARK: - 디버그 | ||
static func debug(_ message: Any, _ arguments: Any...) { | ||
log(message, arguments, level: .debug) | ||
} | ||
|
||
//MARK: - 문제 해결시 활용할 수 있는, 도움이 되지만 필수적이지 않은 정보 로거 | ||
/** | ||
# info | ||
- Authors : suni | ||
- Note : 문제 해결시 활용할 수 있는, 도움이 되지만 필수적이지 않은 정보 | ||
*/ | ||
static func info(_ message: Any, _ arguments: Any...) { | ||
log(message, arguments, level: .info) | ||
} | ||
|
||
|
||
//MARK: - 네트워크 로거 | ||
static func network(_ message: Any, _ arguments: Any...) { | ||
log(message, arguments, level: .network) | ||
} | ||
|
||
//MARK: - 에러 로거 | ||
static func error(_ message: Any, _ arguments: Any...) { | ||
log(message, arguments, level: .error) | ||
} | ||
|
||
//MARK: - 커스텀 로거 | ||
static func custom(category: String, _ message: Any, _ arguments: Any...) { | ||
log(message, arguments, level: .custom(category: category)) | ||
} | ||
|
||
} | ||
|
18 changes: 18 additions & 0 deletions
18
iOS/RollTheDice/RollTheDice/Source/Domain/Service/Log/Extension+OSLog.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,18 @@ | ||
// | ||
// Extension+OSLog.swift | ||
// RollTheDice | ||
// | ||
// Created by Subeen on 5/14/24. | ||
// | ||
|
||
import Foundation | ||
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 info = OSLog(subsystem: subsystem, category: "Info") | ||
static let error = OSLog(subsystem: subsystem, category: "Error") | ||
} | ||
|
99 changes: 99 additions & 0 deletions
99
iOS/RollTheDice/RollTheDice/Source/Domain/Service/Log/Log.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,99 @@ | ||
// | ||
// Log.swift | ||
// RollTheDice | ||
// | ||
// Created by Subeen on 5/14/24. | ||
// | ||
|
||
import Foundation | ||
import OSLog | ||
|
||
public struct Log { | ||
public init(){} | ||
|
||
public enum LogLevel { | ||
/// 디버깅 로그 | ||
case debug | ||
/// 문제 해결 정보 | ||
case info | ||
/// 네트워크 로그 | ||
case network | ||
/// 오류 로그 | ||
case error | ||
case custom(category: String) | ||
|
||
fileprivate var category: String { | ||
switch self { | ||
case .debug: | ||
return "🟡 DEBUG" | ||
case .info: | ||
return "🟠 INFO" | ||
case .network: | ||
return "🔵 NETWORK" | ||
case .error: | ||
return "🔴 ERROR" | ||
case .custom(let category): | ||
return "🟢 \(category)" | ||
} | ||
} | ||
|
||
fileprivate var osLog: OSLog { | ||
switch self { | ||
case .debug: | ||
return OSLog.debug | ||
case .info: | ||
return OSLog.info | ||
case .network: | ||
return OSLog.network | ||
case .error: | ||
return OSLog.error | ||
case .custom: | ||
return OSLog.debug | ||
} | ||
} | ||
|
||
fileprivate var osLogType: OSLogType { | ||
switch self { | ||
case .debug: | ||
return .debug | ||
case .info: | ||
return .info | ||
case .network: | ||
return .default | ||
case .error: | ||
return .error | ||
case .custom: | ||
return .debug | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
static func log(_ message: Any, _ arguments: [Any], level: LogLevel) { | ||
#if DEBUG | ||
if #available(iOS 14.0, *) { | ||
let extraMessage: String = arguments.map({ String(describing: $0) }).joined(separator: " ") | ||
let logger = Logger(subsystem: OSLog.subsystem, category: level.category) | ||
let logMessage = "\(message) \(extraMessage)" | ||
switch level { | ||
case .debug, | ||
.custom: | ||
logger.debug("\(logMessage, privacy: .public)") | ||
case .info: | ||
logger.info("\(logMessage, privacy: .public)") | ||
case .network: | ||
logger.log("\(logMessage, privacy: .public)") | ||
case .error: | ||
logger.error("\(logMessage, privacy: .public)") | ||
} | ||
} else { | ||
let extraMessage: String = arguments.map({ String(describing: $0) }).joined(separator: " ") | ||
os_log("%{public}@", log: level.osLog, type: level.osLogType, "\(message) \(extraMessage)") | ||
} | ||
#endif | ||
} | ||
} | ||
|
||
|
96 changes: 96 additions & 0 deletions
96
iOS/RollTheDice/RollTheDice/Source/Domain/Service/Log/MoyaLoggingPlugin.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,96 @@ | ||
// | ||
// MoyaLoggingPlugin.swift | ||
// RollTheDice | ||
// | ||
// Created by Subeen on 5/14/24. | ||
// | ||
|
||
// 네트워킹 로그 확인 | ||
|
||
import UIKit | ||
import Moya | ||
import OSLog | ||
|
||
public class MoyaLoggingPlugin: PluginType { | ||
|
||
public init() {} | ||
|
||
public func prepare(_ request: URLRequest, target: TargetType) -> URLRequest { | ||
return request | ||
} | ||
// Request를 보낼 때 호출 | ||
public func willSend(_ request: RequestType, target: TargetType) { | ||
guard let httpRequest = request.request else { | ||
#if DEBUG | ||
Log.network("--> 유효하지 않은 요청", (Any).self) | ||
#endif | ||
return | ||
} | ||
|
||
let url = httpRequest.description | ||
let method = httpRequest.httpMethod ?? "메소드값이 nil입니다." | ||
var log = """ | ||
⎡---------------------서버통신을 시작합니다.----------------------⎤ | ||
[\(method)] \(url) | ||
API: \(target) \n | ||
""" | ||
if let headers = httpRequest.allHTTPHeaderFields, !headers.isEmpty { | ||
log.append("header:\n \(headers) \n") | ||
} | ||
if let body = httpRequest.httpBody, let bodyString = String(bytes: body, encoding: String.Encoding.utf8) { | ||
log.append("\(bodyString)\n") | ||
} | ||
|
||
log.append("⎣------------------ Request END -------------------------⎦") | ||
#if DEBUG | ||
Log.network("", log) | ||
#endif | ||
} | ||
// Response가 왔을 때 | ||
public func didReceive(_ result: Result<Response, MoyaError>, target: TargetType) { | ||
switch result { | ||
case let .success(response): | ||
onSucceed(response, target: target, isFromError: false) | ||
case let .failure(error): | ||
onFail(error, target: target) | ||
} | ||
} | ||
|
||
public func process(_ result: Result<Response, MoyaError>, target: TargetType) -> Result<Response, MoyaError> { | ||
return result | ||
} | ||
|
||
public func onSucceed(_ response: Response, target: TargetType, isFromError: Bool) { | ||
let request = response.request | ||
let url = request?.url?.absoluteString ?? "nil" | ||
let statusCode = response.statusCode | ||
var log = "⎡------------------서버에게 Response가 도착했습니다. ------------------⎤\n" | ||
log.append("API: \(target)\n") | ||
log.append("Status Code: [\(statusCode)]\n") | ||
log.append("URL: \(url)\n") | ||
if let responseData = String(bytes: response.data.map{$0}, encoding: String.Encoding.utf8) { | ||
log.append("Data: \n \(responseData)\n") | ||
} | ||
log.append("⎣------------------ END HTTP (\(response.data.count)-byte body) ------------------⎦") | ||
#if DEBUG | ||
|
||
Log.network("", log) | ||
#endif | ||
|
||
} | ||
|
||
public func onFail(_ error: MoyaError, target: TargetType) { | ||
if let response = error.response { | ||
onSucceed(response, target: target, isFromError: true) | ||
return | ||
} | ||
var log = "네트워크 오류" | ||
log.append("<-- \(error.errorCode) \(target)\n") | ||
log.append("\(error.failureReason ?? error.errorDescription ?? "unknown error")\n") | ||
log.append("<-- END HTTP") | ||
#if DEBUG | ||
Log.network("", log) | ||
#endif | ||
|
||
} | ||
} |
Oops, something went wrong.