Skip to content

A Swift macro for automatically adding Loggers to types

License

Notifications You must be signed in to change notification settings

finnvoor/StaticLogger

Repository files navigation

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")

About

A Swift macro for automatically adding Loggers to types

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages