-
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 1 commit
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 |
|---|---|---|
|
|
@@ -4,13 +4,13 @@ import OSLog | |
| public struct Logger { | ||
| private static let subsystem = Bundle.main.bundleIdentifier ?? "com.poppoolIOS.poppool" | ||
|
|
||
| public enum Level { | ||
| public enum Level: Hashable { | ||
| case info | ||
| case debug | ||
| case network | ||
| case error | ||
| case event | ||
| case custom(categoryName: String) | ||
| case custom(name: String) | ||
|
|
||
| var categoryName: String { | ||
| switch self { | ||
|
|
@@ -24,8 +24,7 @@ public struct Logger { | |
| return "Error" | ||
| case .event: | ||
| return "Event" | ||
| case .custom(let categoryName): | ||
| return categoryName | ||
| case .custom(let name): return name | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -45,70 +44,64 @@ public struct Logger { | |
| return "🍎" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public enum LogLevel { | ||
| case debug | ||
| case info | ||
| case error | ||
| case fault | ||
|
|
||
| var osLogType: OSLogType { | ||
| switch self { | ||
| case .debug: | ||
| return .debug | ||
| case .info, .event: | ||
| case .info: | ||
| return .info | ||
| case .network: | ||
| return .default | ||
| case .error: | ||
| return .error | ||
| case .custom: | ||
| return .default | ||
| case .fault: | ||
| return .fault | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static var isShowFileName: Bool = false // 파일 이름 포함여부 | ||
| static var isShowLine: Bool = true // 라인 번호 포함 여부 | ||
| static var isShowLog: Bool = true | ||
| /// : 아래 옵션 주석 해제시 파일명/라인 번호를 로그 메시지에 포함 | ||
| // private static var isShowFileName: Bool = false // 파일 이름 포함 여부 | ||
| // private static var isShowLine: Bool = true // 라인 번호 포함 여부 | ||
| private static var isShowLog: Bool = true | ||
|
|
||
| private static var loggers: [String: os.Logger] = [:] | ||
| private static var loggers: [Level: os.Logger] = [:] | ||
|
||
| private static func getLogger(for category: Level) -> os.Logger { | ||
| let categoryName = category.categoryName | ||
|
|
||
| if let cachedLogger = loggers[categoryName] { | ||
| if let cachedLogger = loggers[category] { | ||
| return cachedLogger | ||
| } | ||
|
|
||
| let logger = os.Logger(subsystem: subsystem, category: categoryName) | ||
| loggers[categoryName] = logger | ||
| loggers[category] = logger | ||
| return logger | ||
| } | ||
|
|
||
| /// : 파일명과 라인 정보 파라미터 포함 | ||
| // public static func log( | ||
| // _ message: Any, | ||
| // category: Level, | ||
| // level: LogLevel = .info, | ||
| // fileName: String = #file, | ||
| // line: Int = #line | ||
| // ) { | ||
| public static func log( | ||
| message: Any, | ||
| _ message: Any, | ||
| category: Level, | ||
| fileName: String = #file, | ||
| line: Int = #line | ||
| level: LogLevel = .info | ||
| ) { | ||
| guard isShowLog else { return } | ||
|
|
||
| let logger = getLogger(for: category) | ||
| var fullMessage = "\(category.categoryIcon) \(message)" | ||
| let 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)") | ||
| } | ||
| logger.log(level: level.osLogType, "\(fullMessage, privacy: .public)") | ||
| } | ||
| } | ||
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.
해당 프로퍼티를 사용하지 않는 것으로 보이는데 어디에서 사용되고 있는지 알 수 있을까요?
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.
이전회의때 영훈님께서 로거의 위치를 알수가없다 하셔서 위와같은 기능이 있기에 추가해뒀다가 현재는 전문 제거되었습니다.