Skip to content

Commit 2b45ac9

Browse files
authored
로그 모듈 추가 (#25)
* 📦 Add Log library * ✏️ Fix typos
1 parent 8cff04a commit 2b45ac9

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

PyeonHaeng-iOS.xcodeproj/project.pbxproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
BA0564092B6248EA003D6DC7 /* HomeAPI in Frameworks */ = {isa = PBXBuildFile; productRef = BA0564082B6248EA003D6DC7 /* HomeAPI */; };
1212
BA05640B2B6248EA003D6DC7 /* HomeAPISupport in Frameworks */ = {isa = PBXBuildFile; productRef = BA05640A2B6248EA003D6DC7 /* HomeAPISupport */; };
1313
BA05640D2B6248EA003D6DC7 /* Network in Frameworks */ = {isa = PBXBuildFile; productRef = BA05640C2B6248EA003D6DC7 /* Network */; };
14+
BA0623D82B68E51400A0A3B2 /* Log in Frameworks */ = {isa = PBXBuildFile; productRef = BA0623D72B68E51400A0A3B2 /* Log */; };
1415
BA28F17C2B6155450052855E /* PyeonHaeng_iOSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA28F17B2B6155450052855E /* PyeonHaeng_iOSTests.swift */; };
1516
BA28F1852B6155810052855E /* OnboardingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA28F1842B6155810052855E /* OnboardingView.swift */; };
1617
BA28F1882B6155910052855E /* HomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA28F1872B6155910052855E /* HomeView.swift */; };
@@ -104,6 +105,7 @@
104105
files = (
105106
BA05640D2B6248EA003D6DC7 /* Network in Frameworks */,
106107
BA05640B2B6248EA003D6DC7 /* HomeAPISupport in Frameworks */,
108+
BA0623D82B68E51400A0A3B2 /* Log in Frameworks */,
107109
BA0564092B6248EA003D6DC7 /* HomeAPI in Frameworks */,
108110
BAB569612B639F3000D1E0F9 /* DesignSystem in Frameworks */,
109111
);
@@ -339,6 +341,7 @@
339341
BA05640A2B6248EA003D6DC7 /* HomeAPISupport */,
340342
BA05640C2B6248EA003D6DC7 /* Network */,
341343
BAB569602B639F3000D1E0F9 /* DesignSystem */,
344+
BA0623D72B68E51400A0A3B2 /* Log */,
342345
);
343346
productName = "PyeonHaeng-iOS";
344347
productReference = BAA4D9A92B5A1795005999F8 /* PyeonHaeng-iOS.app */;
@@ -767,6 +770,10 @@
767770
isa = XCSwiftPackageProductDependency;
768771
productName = Network;
769772
};
773+
BA0623D72B68E51400A0A3B2 /* Log */ = {
774+
isa = XCSwiftPackageProductDependency;
775+
productName = Log;
776+
};
770777
BAB569602B639F3000D1E0F9 /* DesignSystem */ = {
771778
isa = XCSwiftPackageProductDependency;
772779
productName = DesignSystem;

Shared/Package.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@ let package = Package(
1111
name: "DesignSystem",
1212
targets: ["DesignSystem"]
1313
),
14+
.library(
15+
name: "Log",
16+
targets: ["Log"]
17+
),
1418
],
1519
targets: [
1620
.target(
1721
name: "DesignSystem",
1822
resources: [.process("Resources")]
1923
),
24+
.target(name: "Log"),
2025
]
2126
)

Shared/Sources/Log/Log.swift

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//
2+
// Log.swift
3+
//
4+
//
5+
// Created by 홍승현 on 1/30/24.
6+
//
7+
8+
import OSLog
9+
10+
// MARK: - Log
11+
12+
/// 로그
13+
public enum Log {
14+
/// Log를 생성합니다.
15+
/// - Parameter category: Log를 구분하는 Category
16+
public static func make(_ context: some CustomStringConvertible, with logger: Logger, at level: Level) {
17+
#if DEBUG
18+
switch level {
19+
case .debug:
20+
logger.debug("\(context.description)")
21+
case .info:
22+
logger.info("\(context.description)")
23+
case .notice:
24+
logger.notice("\(context.description)")
25+
case .warning:
26+
logger.warning("\(context.description)")
27+
case .fault:
28+
logger.fault("\(context.description)")
29+
}
30+
#endif
31+
}
32+
}
33+
34+
// MARK: Log.Level
35+
36+
public extension Log {
37+
enum Level {
38+
/// Writes a debug message to the log.
39+
case debug
40+
41+
/// Writes an informative message to the log.
42+
case info
43+
44+
/// Writes a message to the log using the default log type.
45+
case notice
46+
47+
/// Writes information about a warning to the log.
48+
case warning
49+
50+
/// Writes a message to the log about a bug that occurs when your app executes.
51+
case fault
52+
}
53+
}
54+
55+
public extension Logger {
56+
/// 네트워크 로그를 작성할 때 사용합니다.
57+
static let network = Logger(subsystem: .bundleIdentifier, category: "network")
58+
59+
/// 뷰에 관한 로그를 작성할 때 사용합니다.
60+
static let view = Logger(subsystem: .bundleIdentifier, category: "view")
61+
62+
/// 뷰모델에 관한 로그를 작성할 때 사용합니다.
63+
static let viewModel = Logger(subsystem: .bundleIdentifier, category: "viewModel")
64+
}
65+
66+
private extension String {
67+
static let bundleIdentifier: String = Bundle.main.bundleIdentifier ?? "None"
68+
}

0 commit comments

Comments
 (0)