https://github.com/marekpridal/logkit
Swift framework for easy logging
https://github.com/marekpridal/logkit
ios logger logging macos swift swift-pm watch xcframework
Last synced: about 1 month ago
JSON representation
Swift framework for easy logging
- Host: GitHub
- URL: https://github.com/marekpridal/logkit
- Owner: marekpridal
- License: mit
- Created: 2020-05-04T13:00:25.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2025-02-09T21:30:33.000Z (over 1 year ago)
- Last Synced: 2025-03-10T23:03:28.250Z (about 1 year ago)
- Topics: ios, logger, logging, macos, swift, swift-pm, watch, xcframework
- Language: Swift
- Size: 316 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# LogKit
    [](https://github.com/apple/swift-package-manager)  
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.
### [Xcode](https://developer.apple.com/documentation/xcode/adding_package_dependencies_to_your_app)
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](https://github.com/) or [GitHub Enterprise](https://github.com/enterprise). Add your [GitHub](https://github.com/) or [GitHub Enterprise](https://github.com/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.
### [Swift Package Manager](https://github.com/apple/swift-package-manager)
Create a `Package.swift` file.
```swift
// 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
```swift
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------------------
//
// ----------------------------
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------------------
//
// ----------------------------
Log.paymentQueue(queue)
// 2020-05-10 15:42:58.838761+0200 xctest[11254:225150] [inAppPurchase]
// ---QUEUE------------------
//
// ----------------------------
Log.payment(transactions: transactions)
// 2020-05-10 15:43:17.628385+0200 xctest[11281:225904] [inAppPurchase]
// ---UPDATED TRANSACTIONS------------------
// []
// ----------------------------
```