Skip to content

Commit 3381365

Browse files
committed
modify
1 parent 9f8a1d5 commit 3381365

File tree

7 files changed

+73
-53
lines changed

7 files changed

+73
-53
lines changed

Sources/Implementation/Member/LoggingMacro.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public struct LoggingMacro: MemberMacro {
3737
DeclSyntax(
3838
"""
3939
lazy var logger: OSLog = {
40-
LoggingMacroHelper.generateOSLog(category: \(raw: category))
40+
GenerateOSLog(category: \(raw: category)).log
4141
}()
4242
"""),
4343
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Foundation
2+
3+
// MARK: - Associated Values
4+
5+
@attached(member, names: arbitrary)
6+
public macro AssociatedValues(_ accessLevel: AccessLevelConfig? = nil) = #externalMacro(module: "Macros", type: "AssociatedValuesMacro")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Foundation
2+
3+
// MARK: - Case Detection
4+
5+
/// Add computed properties named `is<Case>` for each case element in the enum.
6+
@attached(member, names: named(init), arbitrary)
7+
public macro CaseDetection(_ accessLevel: AccessLevelConfig? = nil) = #externalMacro(module: "Macros", type: "CaseDetectionMacro")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import Foundation
2+
3+
@_exported import OSLog
4+
5+
// MARK: - Logging
6+
7+
@attached(member, names: named(logger))
8+
public macro Logging(category: String? = nil) = #externalMacro(module: "Macros", type: "LoggingMacro")
9+
10+
// MARK: - Helper
11+
12+
public struct GenerateOSLog {
13+
public let log: OSLog
14+
15+
public init(_ fileID: String = #fileID, category: String) {
16+
let (module, fileName) = {
17+
let list = fileID.components(separatedBy: "/")
18+
return (list.first, list.last?.components(separatedBy: ".").first)
19+
}()
20+
21+
guard let module,
22+
let fileName
23+
else {
24+
log = .default
25+
return
26+
}
27+
28+
let subsystem = "kr.minsone.\(module).\(fileName)"
29+
log = OSLog(subsystem: subsystem, category: category)
30+
}
31+
}

Sources/Interface/MemberMacros.swift

-49
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by minsOne on 4/25/24.
6+
//
7+
8+
import Foundation
9+
10+
public enum ClassAccessLevelConfig {
11+
case `private`
12+
case `fileprivate`
13+
case `internal`
14+
case `package`
15+
case `public`
16+
case `open`
17+
}
18+
19+
public enum AccessLevelConfig {
20+
case `private`
21+
case `fileprivate`
22+
case `internal`
23+
case `package`
24+
case `public`
25+
}

Tests/MacroKitTests/Member/LoggingTests.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ final class LoggingTests: XCTestCase {
1515
class TestingObject {
1616
1717
lazy var logger: OSLog = {
18-
LoggingMacroHelper.generateOSLog(category: String(describing: Self.self))
18+
GenerateOSLog(category: String(describing: Self.self)).log
1919
}()
2020
}
2121
""",
@@ -42,7 +42,7 @@ final class LoggingTests: XCTestCase {
4242
}
4343
4444
lazy var logger: OSLog = {
45-
LoggingMacroHelper.generateOSLog(category: String(describing: Self.self))
45+
GenerateOSLog(category: String(describing: Self.self)).log
4646
}()
4747
}
4848
""",
@@ -69,7 +69,7 @@ final class LoggingTests: XCTestCase {
6969
}
7070
7171
lazy var logger: OSLog = {
72-
LoggingMacroHelper.generateOSLog(category: "UI")
72+
GenerateOSLog(category: "UI").log
7373
}()
7474
}
7575
""",

0 commit comments

Comments
 (0)