StaticLogger
A simple Swift macro that adds a static logger
method to a class, struct, actor, or enum, with a default subsystem and category based on the bundle identifier and type name.
Usage
import OSLog
import StaticLogger
@StaticLogger
struct MyStruct {
let x: Int
func test() {
Self.logger.debug("X is \(x)")
}
}
Expands to:
struct MyStruct {
let x: Int
func test() {
Self.logger.debug("X is \(x)")
}
static let logger = Logger(subsystem: Bundle.main.bundleIdentifier ?? "", category: "MyStruct")
}
You can also override the logger’s subsystem or category by passing them to @StaticLogger
:
@StaticLogger(subsystem: "MySubsystem", category: "MyCategory")