LogKit

3.0.0

Swift framework for easy logging
marekpridal/LogKit

What's New

Release 3.0.0

2025-02-09T21:30:47Z

Commits

  • 4e321ee: Update README (Marek Pridal)
  • b92a77d: Add Swift Android Native dependency (Marek Pridal) #10
  • f3c87a2: Add android to github actions (Marek Pridal) #10
  • 0512bd5: Update github actions (Marek Pridal) #10
  • 30f8779: WIP (Marek Pridal) #10
  • 833c177: Compile on Android (Marek Pridal) #10
  • b357c36: Migrate to Logger (Marek Pridal) #10
  • 0d75a29: Update README (Marek Pridal) #10
  • ff7e857: Log error as error type (Marek Pridal)

LogKit

Build Test Publish platforms Swift Package Manager compatible GitHub GitHub All Releases

LogKit is logging framework to simplify work with os.log API provided by Apple.

Support

  • iOS 14.0+
  • watchOS 7.0+
  • macOS 11+
  • tvOS 14.0+
  • visionOS 1.0+
  • Android

Installation

LogKit supports SwiftPM. You can integrate LogKit using SwiftPM directly via Xcode or manually using Package.swift.

To add a package dependency to your Xcode project, select File > Swift Packages > Add Package Dependency and enter its repository URL. You can also navigate to your target’s General pane, and in the “Frameworks, Libraries, and Embedded Content” section, click the + button. In the “Choose frameworks and libraries to add” dialog, select Add Other, and choose Add Package Dependency.

Instead of adding a repository URL, you can search for a package on GitHub or GitHub Enterprise. Add your GitHub or GitHub Enterprise account in Xcode’s preferences, and a list of package repositories appears as you type. The following screenshot shows the list of repositories for the search term ExamplePackage.

Create a Package.swift file.

// swift-tools-version:6.0

import PackageDescription

let package = Package(
  name: "LogKitExample",
  dependencies: [
    .package(url: "https://github.com/marekpridal/LogKit", from: "3.0.0")
  ],
  targets: [
    .target(name: "LogKitExample", dependencies: ["LogKit"])
  ]
)

Usage

import LogKit

// Configure what should be logged during session
Log.enabledLogging = [.default, .error, .expiration, .function, .inAppPurchase, .networking]

Log.deinit(of: self)

// 2020-05-10 15:34:17.452379+0200 xctest[10906:217188] [deinit] Deinit of -[LogKitTests testLogDeinit]

Log.default("Hello world")

// 2020-05-10 15:34:17.451431+0200 xctest[10906:217188] [default] Hello world

Log.error(NSError(domain: "logkit.tests", code: 0, userInfo: nil))

// 2020-05-10 15:34:17.454305+0200 xctest[10906:217188] [error] Unable to complete (logkit.tests error 0.)


Log.function(#function, in: #file)

// 2020-05-10 15:34:17.455434+0200 xctest[10906:217188] [function] testLogFunctionIn() LogKitTests/LogKitTests.swift


Log.requestCalled(function: #function)

// 2020-05-10 15:34:17.465002+0200 xctest[10906:217188] [networking] testLogRequestCalled() already called

Log.expiration(date: expiresDate)

// 2020-05-10 15:34:17.454920+0200 xctest[10906:217188] [expiration] [GMT] Valid until 2020-05-10 13:34:17 +0000

Log.request(URLRequest(url: URL(string: "https://github.com/marekpridal/LogKit")!, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 30))

// 2020-05-10 15:34:17.458338+0200 xctest[10906:217188] [networking] 
// ---REQUEST------------------
// URL -> https://github.com/marekpridal/LogKit
// METHOD -> GET
// HEADERS: {
// }
// ----------------------------

Log.response(response, data: data)

// ---RESPONSE------------------
// URL -> https://github.com/marekpridal/LogKit
// MIMEType -> application/octet-stream
// Status code -> -1
// HEADERS: {
// }
// Response data -> {"bar":"Hello world"}
// ----------------------------

Log.function(#function, text: "Log function")

// 2020-05-10 15:34:17.455465+0200 xctest[10906:217188] [function] testLogFunctionIn() Log function

Log.inAppPurchase("Purchasing...")

// 2020-05-10 15:34:17.455969+0200 xctest[10906:217188] [inAppPurchase] Purchasing...

Log.products(request: request)

// 2020-05-10 15:41:25.661150+0200 xctest[11170:222169] [inAppPurchase] 
// ---REQUEST------------------
// <SKProductsRequest: 0x100bb6670>
// ----------------------------

Log.products(response: response)

// 2020-05-10 15:41:48.995140+0200 xctest[11187:222918] [inAppPurchase] 
// ---RESPONSE------------------
// Invalid product identifiers []
// ----------------------------
// Products []
// ----------------------------

Log.products(request: request)

// 2020-05-10 15:42:30.262523+0200 xctest[11204:223751] [inAppPurchase] 
// ---REQUEST------------------
// <SKProductsRequest: 0x100b09130>
// ----------------------------

Log.paymentQueue(queue)

// 2020-05-10 15:42:58.838761+0200 xctest[11254:225150] [inAppPurchase] 
// ---QUEUE------------------
// <SKPaymentQueue: 0x100f07ee0>
// ----------------------------

Log.payment(transactions: transactions)

// 2020-05-10 15:43:17.628385+0200 xctest[11281:225904] [inAppPurchase] 
// ---UPDATED TRANSACTIONS------------------
// [<SKPaymentTransaction: 0x1051040a0>]
// ----------------------------

Description

  • Swift Tools 6.0.0
View More Packages from this Author

Dependencies

Last updated: Fri May 16 2025 09:32:45 GMT-0900 (Hawaii-Aleutian Daylight Time)