Skip to content
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

[GWL-52] Logger 모듈 생성 #101

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public extension TargetDependency {
static let trinet: TargetDependency = .project(target: "Trinet", path: .relativeToCore("Network"))
static let coordinator: TargetDependency = .project(target: "Coordinator", path: .relativeToCore("Coordinator"))
static let combineCocoa: TargetDependency = .project(target: "CombineCocoa", path: .relativeToShared("CombineCocoa"))
static let log: TargetDependency = .project(target: "Log", path: .relativeToShared("Log"))

static func feature(_ feature: Feature) -> TargetDependency {
return .project(
Expand Down
2 changes: 1 addition & 1 deletion iOS/Projects/Features/Record/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let project = Project.makeModule(
targets: .feature(
.record,
testingOptions: [.unitTest],
dependencies: [.trinet, .designSystem, .combineCocoa, .coordinator],
dependencies: [.trinet, .designSystem, .combineCocoa, .coordinator, .log],
testDependencies: [.trinet, .designSystem, .combineCocoa],
resources: "Resources/**"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import DesignSystem
import OSLog
import UIKit

// MARK: - WorkoutEnvironmentSetupViewController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Combine
import CoreLocation
import DesignSystem
import MapKit
import OSLog
import Log
import UIKit

// MARK: - WorkoutRouteMapViewController
Expand Down Expand Up @@ -117,7 +117,7 @@ extension WorkoutRouteMapViewController: CLLocationManagerDelegate {
manager.authorizationStatus == .authorizedWhenInUse
|| manager.authorizationStatus == .authorizedAlways
else {
Logger().error("유저의 위치를 받아올 수 없습니다.")
Log.make().error("유저의 위치를 받아올 수 없습니다.")
return
}
locationManager.startUpdatingLocation()
Expand All @@ -126,7 +126,7 @@ extension WorkoutRouteMapViewController: CLLocationManagerDelegate {
func locationManager(_: CLLocationManager, didUpdateLocations newLocations: [CLLocation]) {
guard let newLocation = newLocations.last
else {
Logger().error("location 값이 존재하지 않습니다.")
Log.make().error("location 값이 존재하지 않습니다.")
return
}

Expand All @@ -145,7 +145,7 @@ extension WorkoutRouteMapViewController: CLLocationManagerDelegate {
}

func locationManager(_: CLLocationManager, didFailWithError error: Error) {
Logger().error("\(error)")
Log.make().error("\(error)")
}
}

Expand Down
7 changes: 7 additions & 0 deletions iOS/Projects/Shared/Log/Project.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import ProjectDescription
import ProjectDescriptionHelpers

let project = Project.makeModule(
name: "Log",
targets: .custom(name: "Log", product: .framework)
)
38 changes: 38 additions & 0 deletions iOS/Projects/Shared/Log/Sources/Logger.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// Log.swift
// DesignSystem
//
// Created by 홍승현 on 11/23/23.
// Copyright © 2023 kr.codesquad.boostcamp8. All rights reserved.
//

import OSLog

/// 로그
public enum Log {

/// Logger를 생성합니다.
/// - Parameter category: Log를 구분하는 Category
public static func make(with category: LogCategory = .default) -> Logger {
return Logger(subsystem: .bundleIdentifier, category: category.rawValue)
}
}


/// 로그 카테고리
public enum LogCategory: String {

/// 기본값으로 들어갑니다.
case `default`

/// UI 로그를 작성할 때 사용합니다.
case userInterface

/// 네트워크 로그를 작성할 때 사용합니다.
case network
}


private extension String {
static let bundleIdentifier: String = Bundle.main.bundleIdentifier ?? "None"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3

이거 번들 아이덴티파이어 항상 wetri로 출력되나요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맞습니다. 이렇게 해도 괜찮겠다 싶었는데.. 지금 보니까 다시 생각이 바뀌었어요. 모듈마다 bundleIdentifier로 보이도록 수정할게요.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

다행히 로그에서는 모듈별로 로깅이 보이도록 해주네요! 따로 수정 안해도 될 것 같습니다 :)
image

}
8 changes: 0 additions & 8 deletions iOS/Projects/Shared/Project.swift

This file was deleted.

Loading