Loggable

1.0.1

A Swift macro that provides a convenient way to add an OSLog.Logger instance to your classes, structs, enums, and actors.
00yhsp/Loggable

What's New

1.0.1

2025-11-10T18:09:01Z

Full Changelog: 1.0.0...1.0.1

Loggable

A Swift macro that provides a convenient way to add an OSLog.Logger instance to your classes, structs, enums, and actors.

Features

  • Automatic Logger Injection: Automatically synthesizes a logger property of type OSLog.Logger.
  • Configurable Category: Allows specifying a custom category for the logger. If no category is provided, it defaults to the type's name.
  • Subsystem based on Bundle ID: The logger's subsystem is automatically derived from the bundle identifier of the current module or the process name.

Usage

To use the @Loggable macro, simply apply it to your class, struct, enum, or actor declaration.

Basic Usage

import Loggable

@Loggable
class MyService {
    func doSomething() {
        logger.info("Doing something important.")
    }
}

@Loggable
struct MyViewModel {
    func loadData() {
        logger.debug("Loading data for view model.")
    }
}

With Custom Category

You can provide a custom category string as an argument to the macro:

import Loggable

@Loggable("Networking")
class NetworkManager {
    func fetchData() {
        logger.debug("Fetching data from server.")
    }
}

@Loggable("Database")
enum DatabaseError: Error {
    case connectionFailed
    case queryFailed

    func logError() {
        logger.error("Database error occurred: \(self.localizedDescription)")
    }
}

Installation

Swift Package Manager

Add Loggable as a dependency to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/your-username/Loggable.git", from: "1.0.0"),
],
targets: [
    .target(
        name: "YourTarget",
        dependencies: ["Loggable"]
    ),
    .macro(
        name: "LoggableMacros",
        dependencies: [
            .product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
            .product(name: "SwiftCompilerPlugin", package: "swift-syntax")
        ]
    ),
]

Then, add Loggable to your target's dependencies:

.product(name: "Loggable", package: "Loggable"),

Requirements

  • Swift 5.9+
  • Xcode 15+
  • iOS 17.0+ / macOS 14.0+ / tvOS 17.0+ / watchOS 10.0+

License

This project is licensed under the MIT License - see the LICENSE file for details.

Description

  • Swift Tools 6.1.0
View More Packages from this Author

Dependencies

Last updated: Sun Feb 22 2026 00:00:54 GMT-1000 (Hawaii-Aleutian Standard Time)