grdsdev/swift-logflare
A Swift package for sending logs to [Logflare](https://logflare.app/).
Requirements
- iOS 15.0+
- macOS 12.0+
- tvOS 15.0+
- watchOS 8.0+
- Swift 6.0+
Installation
Swift Package Manager
Add the following to your Package.swift file:
dependencies: [
.package(url: "https://github.com/grdsdev/swift-logflare.git", from: "0.1.0")
]Or add it through Xcode:
- File → Add Package Dependencies
- Enter the repository URL
- Select the version and add to your target
Usage
Basic Setup
import Logflare
// Create client options
let options = ClientOptions(
sourceToken: "your-source-token",
apiKey: "your-api-key"
)
// Initialize the client
let logflare = try Logflare(options: options)Sending Events
Single Event
let event = [
"message": "Hello from Swift!",
"level": "info",
"timestamp": Date().timeIntervalSince1970
]
let response = try await logflare.sendEvent(event)
print(response.message) // "Success"Multiple Events
let events = [
["message": "Event 1", "level": "info"],
["message": "Event 2", "level": "error"],
["message": "Event 3", "level": "debug"]
]
let response = try await logflare.sendEvents(events)
print(response.message) // "Success"Error Handling
let options = ClientOptions(
sourceToken: "your-source-token",
apiKey: "your-api-key",
onError: { payload, error in
print("Logflare error: \(error.localizedDescription)")
}
)
do {
let response = try await logflare.sendEvent(event)
print("Success: \(response.message)")
} catch {
print("Failed to send event: \(error.localizedDescription)")
}Custom API URL
let options = ClientOptions(
sourceToken: "your-source-token",
apiKey: "your-api-key",
apiURL: URL(string: "https://your-custom-logflare-instance.com")
)API Reference
ClientOptions
sourceToken: String- Your Logflare source token (required)apiKey: String- Your Logflare API key (required)apiURL: URL?- Custom API URL (optional, defaults to https://api.logflare.app)onError: (( payload: [String: Any], error: Error) -> Void)?- Error callback (optional)
Logflare
init(options: ClientOptions) throws- Initialize the clientsendEvent(_ event: [String: Any]) async throws(LogflareError) -> LogflareResponse- Send a single eventsendEvents(_ batch: [[String: Any]]) async throws(LogflareError) -> LogflareResponse- Send multiple events
LogflareResponse
message: String- Response message from Logflare
License
This project is licensed under the MIT License.
Package Metadata
Repository: grdsdev/swift-logflare
Default branch: main
README: README.md