-
Notifications
You must be signed in to change notification settings - Fork 0
[FEAT] #127 OSLog도입 #128
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] #127 OSLog도입 #128
Changes from 2 commits
ec3f787
09d15eb
a04857f
8f3e675
4444ed3
e014ccd
b5a134f
93592c9
2c17a4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| import Foundation | ||
| import OSLog | ||
|
|
||
| public struct Logger { | ||
| private static let subsystem = Bundle.main.bundleIdentifier ?? "com.poppoolIOS.poppool" | ||
|
|
||
| public enum Level { | ||
| case info | ||
| case debug | ||
|
|
@@ -42,28 +45,70 @@ public struct Logger { | |
| return "🍎" | ||
| } | ||
| } | ||
|
|
||
| var osLogType: OSLogType { | ||
| switch self { | ||
| case .debug: | ||
| return .debug | ||
| case .info, .event: | ||
| return .info | ||
| case .network: | ||
| return .default | ||
| case .error: | ||
| return .error | ||
| case .custom: | ||
| return .default | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static var isShowFileName: Bool = false | ||
| static var isShowLine: Bool = false | ||
| static var isShowFileName: Bool = false // 파일 이름 포함여부 | ||
| static var isShowLine: Bool = true // 라인 번호 포함 여부 | ||
| static var isShowLog: Bool = true | ||
|
|
||
| private static var loggers: [String: os.Logger] = [:] | ||
|
||
| private static func getLogger(for category: Level) -> os.Logger { | ||
| let categoryName = category.categoryName | ||
|
|
||
| if let cachedLogger = loggers[categoryName] { | ||
| return cachedLogger | ||
| } | ||
|
|
||
| let logger = os.Logger(subsystem: subsystem, category: categoryName) | ||
| loggers[categoryName] = logger | ||
| return logger | ||
| } | ||
|
||
|
|
||
| public static func log( | ||
| message: Any, | ||
| category: Level, | ||
| fileName: String = "Input is not found", | ||
| line: Int? = nil | ||
| fileName: String = #file, | ||
| line: Int = #line | ||
|
||
| ) { | ||
| if isShowLog { | ||
| print("\(category.categoryIcon) [\(category.categoryName)]: \(message)") | ||
| if isShowFileName { | ||
| guard let fileName = fileName.components(separatedBy: "/").last else { return } | ||
| print(" \(category.categoryIcon) [FileName]: \(fileName)") | ||
| } | ||
| if isShowLine { | ||
| guard let line = line else { return } | ||
| print(" \(category.categoryIcon) [Line]: \(line)") | ||
| } | ||
| guard isShowLog else { return } | ||
|
|
||
| let logger = getLogger(for: category) | ||
| var fullMessage = "\(category.categoryIcon) \(message)" | ||
|
|
||
| if isShowFileName { | ||
| guard let fileNameOnly = fileName.components(separatedBy: "/").last else { return } | ||
| fullMessage += " | 📁 \(fileNameOnly)" | ||
| } | ||
|
|
||
| if isShowLine { | ||
| fullMessage += " | 📍 \(line)" | ||
| } | ||
|
|
||
| logger.log(level: category.osLogType, "\(fullMessage, privacy: .public)") | ||
|
|
||
| // 디버깅 시 Xcode 콘솔에서도 바로 확인할 수 있도록 print도 함께 사용 불필요시 제거 | ||
| print("\(category.categoryIcon) [\(category.categoryName)]: \(message)") | ||
| if isShowFileName { | ||
| guard let fileNameOnly = fileName.components(separatedBy: "/").last else { return } | ||
| print(" \(category.categoryIcon) [FileName]: \(fileNameOnly)") | ||
| } | ||
| if isShowLine { | ||
| print(" \(category.categoryIcon) [Line]: \(line)") | ||
|
||
| } | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 혹시 이미지 파일이 이번 로거 작업이랑은 연관이 없어 보이는데 제거좀 해주실 수 있을까요? 그리고 이미지 추가하실때 svg로 추출하고 single scale로 적용해주시는게 이미지의 크기가 변경되는 상황에서 유리합니다! 지금 다른 작업의 내용에서 방금 말씀드린 svg 변경 적용해서 작업하시면 좋을것 같아요 |

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기서 사용되는 변수가 내부에서만 사용되는것 같은데 private로 감싸주거나 이 변수를 필요로하는 메서드 내부에서 let으로 선언해줘도 좋아보입니다☺️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private으로 따뜻하게 감싸줬습니다..