Exposes an opinionated os.Logger
through Swift Package Plugins and Swift Macros
- Assure that your supported platforms are compatible:
let package = Package(
// ...
platforms: [
.macOS(.v13),
.iOS(.v16),
.tvOS(.v16),
.watchOS(.v9),
.macCatalyst(.v16),
.visionOS(.v1)
],
// ...
)
- Add
Logs
to your dependencies:
let package = Package(
// ...
dependencies: [
.package(name: "Logs", url: "https://github.com/rewardStyle/Logs"),
],
// ...
)
- Add
Logs
library dependency andGenerateLogger
plugin to your target:
let package = Package(
// ...
targets: [
.target(
name: "CatsAreCool",
dependencies: [
.product(name: "Logs", package: "Logs"),
],
plugins: [
.plugin(name: "GenerateLogger", package: "Logs")
]
)
]
// ...
)
- Build your project and trust the macro execution in Xcode
- Add
Logs
to your Swift Package Dependencies in Xcode - Add
Logs
library to your "Frameworks, Libraries, and Embedded Content" section. - Navigate to Project -> Target -> Build Phases -> Run Build Tool Plug-ins and add
GenerateLogger (Logs)
- Build your project and trust the macro execution in Xcode
Add the @Logging
attribute to your declaration and a new os.Logger
static instance is generated on your object:
import Logs
@Logging
struct Cat {
func meow() {
Self.logger.log("Meow!")
}
}
Simply use it by calling:
Self.logger.log("Meow!")
For more information about Apple's os.Logger
, check out their documentation https://developer.apple.com/documentation/os/logger.