Skip to content

IT-Guy007/Club-LoggingKit

Repository files navigation

Club-LoggingKit

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.

What this project provides

This package ships three products:

  • Club-LoggingKit (library): public logging macros and global logging config
  • Club-LoggingManager (library): Crashlytics management helper (CrashlyticsManager)
  • Club-LoggingKitClient (executable): small usage/demo target in this repo

Features

  • 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)
  • Optional release OSLog mirroring via launch argument: -ClubOSLog
  • Crashlytics management API (CrashlyticsManager) for user IDs, custom keys, report upload, and reset

Requirements

  • Swift tools: 6.1
  • Platforms:
    • iOS 15+
    • macOS 11+
    • tvOS 13+
    • watchOS 6+
    • Mac Catalyst 13+
  • Firebase Crashlytics (resolved via Swift Package Manager)

Installation (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")
    ]
)

Usage

1) Import modules

import Club_LoggingKit
import Club_LoggingManager
import OSLog

2) Basic logging

let logger = Logger(subsystem: "com.example.app", category: "network")

#log(level: .info, "App started")
#log(logger: logger, level: .debug, "Fetching profile")

3) Error logging

do {
    try performWork()
} catch {
    #logError(logger: logger, error: error, "Failed to perform work")
}

4) Logged try helpers

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()
}

Release OSLog toggle

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.

CrashlyticsManager example

let manager = CrashlyticsManager()
manager.setUserID(id: "user-123")
manager.setCustomValue(key: .scene, value: "checkout")
manager.forceUploadReports()

Available LoggingKeys cases:

  • .loginProvider
  • .loginstate
  • .scene

Development

Run tests:

swift test

License

This project is licensed under the terms in LICENSE.

About

A set of macros simplified logging and error reporting in swift, to automatically switch between oslog and crashlytics

Resources

License

Stars

Watchers

Forks

Contributors

Languages