A Swift logging package that combines compile-time logging macros with Firebase Crashlytics reporting.
In Debug builds, logs go to OSLog.
In Release builds, logs go to Crashlytics, with optional OSLog output enabled by launch argument.
This package ships three products:
Club-LoggingKit(library): public logging macros and global logging configClub-LoggingManager(library): Crashlytics management helper (CrashlyticsManager)Club-LoggingKitClient(executable): small usage/demo target in this repo
- Freestanding logging macros:
#log(logger:level:_:)#log(level:_:)#logError(logger:error:_:)#loggedTry(logger:failureMessage:_:)#loggedTryAsync(logger:failureMessage:_:)
- Automatic behavior split by build configuration:
- Debug:
OSLog - Release: Crashlytics (+ optional
OSLog)
- Debug:
- Optional release
OSLogmirroring via launch argument:-ClubOSLog - Crashlytics management API (
CrashlyticsManager) for user IDs, custom keys, report upload, and reset
- Swift tools: 6.1
- Platforms:
- iOS 15+
- macOS 11+
- tvOS 13+
- watchOS 6+
- Mac Catalyst 13+
- Firebase Crashlytics (resolved via Swift Package Manager)
Add this dependency in your Package.swift:
dependencies: [
.package(url: "https://github.com/IT-Guy007/Club-LoggingKit", from: "0.1.10")
]Then add products to your target:
.target(
name: "YourTarget",
dependencies: [
.product(name: "Club-LoggingKit", package: "Club-LoggingKit"),
.product(name: "Club-LoggingManager", package: "Club-LoggingKit")
]
)import Club_LoggingKit
import Club_LoggingManager
import OSLoglet logger = Logger(subsystem: "com.example.app", category: "network")
#log(level: .info, "App started")
#log(logger: logger, level: .debug, "Fetching profile")do {
try performWork()
} catch {
#logError(logger: logger, error: error, "Failed to perform work")
}let result = #loggedTry<String>(logger: logger, failureMessage: "Failed to load") {
try loadValue()
}
let asyncResult = await #loggedTryAsync<String>(logger: logger, failureMessage: "Failed to fetch") {
try await fetchValue()
}By default, release logs go to Crashlytics only.
To also mirror release logs to OSLog, add this launch argument in your run scheme:
-ClubOSLog
This is read by ClubLogging.osLogEnabled.
let manager = CrashlyticsManager()
manager.setUserID(id: "user-123")
manager.setCustomValue(key: .scene, value: "checkout")
manager.forceUploadReports()Available LoggingKeys cases:
.loginProvider.loginstate.scene
Run tests:
swift testThis project is licensed under the terms in LICENSE.