The official Swift SDK for LogFlux. Send logs, metrics, traces, events, and audit entries directly to the LogFlux cloud with end-to-end encryption from iOS and macOS apps. The server never sees your plaintext data.
GitHub Repository ยท Release Notes
Key Features
- End-to-end encryption – AES-256-GCM with RSA key exchange
- 7 entry types – Log, Metric, Trace, Event, Audit, Telemetry, TelemetryManaged
- Multipart binary transport – 33% less overhead than JSON + base64
- Disk persistence – Entries survive app termination and network outages
- Async by default – Non-blocking queue with background workers
- Breadcrumbs – Automatic trail of recent events attached to error captures
- Distributed tracing – Spans, child spans, context propagation
- Scopes – Per-request context isolation
- Keychain storage – AES keys stored securely in iOS/macOS Keychain
- Failsafe – SDK errors never crash your application
- Zero external dependencies – Apple frameworks only
Installation
Swift Package Manager
Add to your Package.swift:
| |
Or in Xcode: File > Add Package Dependencies > enter the repository URL.
Quick Start
| |
Entry Types
Log (Type 1)
Standard application logs with 8 severity levels.
| |
Metric (Type 2)
Counters, gauges, and distributions.
| |
Event (Type 4)
Discrete application events.
| |
Audit (Type 5)
Immutable audit trail with Object Lock storage (365-day retention).
| |
Trace (Type 3)
Distributed tracing with span helpers.
| |
Telemetry (Types 6 and 7)
Device and sensor data. Type 6 is end-to-end encrypted, type 7 is server-side encrypted.
Error Capture
Capture Swift errors with automatic breadcrumb trail.
| |
Breadcrumbs
Breadcrumbs record a trail of events leading up to an error. They are automatically added for log and event calls, and attached to captureError.
| |
Scopes
Per-request context isolation. Attributes set on a scope are merged into every entry.
| |
Trace Context Propagation
Propagate trace context across network requests.
| |
Configuration
Options
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | String | required | API key (<region>-lf_<key>) |
source | String | Service/app name | |
environment | String | Attached to meta.environment | |
release | String | Attached to meta.release | |
queueSize | Int | 1000 | In-memory buffer capacity |
batchSize | Int | 100 | Entries per HTTP request |
workerCount | Int | 2 | Background threads |
maxRetries | Int | 3 | Max retry attempts |
sampleRate | Double | 1.0 | 0.0-1.0, send probability |
maxBreadcrumbs | Int | 100 | Ring buffer size |
failsafe | Bool | true | Never crash host app |
enableCompression | Bool | true | Gzip before encryption |
Environment Variables
| |
Reads LOGFLUX_API_KEY, LOGFLUX_ENVIRONMENT, LOGFLUX_NODE, etc.
BeforeSend Hooks
Filter or modify entries before they are sent. Return nil to drop.
| |
Sampling
| |
Audit entries (type 5) are never sampled.
Disk Persistence
Unlike server-side SDKs, the Swift SDK persists entries to disk before sending. This ensures data survives:
- App suspension/termination by iOS
- Network connectivity loss
- App crashes
Entries are stored in ~/Library/Caches/io.logflux.queue/ with FIFO ordering and automatic eviction.
Security
- Zero-knowledge: All payloads encrypted client-side with AES-256-GCM
- RSA key exchange: AES keys negotiated via RSA-2048 OAEP handshake
- Keychain storage: AES keys stored in iOS/macOS Keychain (whenUnlockedThisDeviceOnly)
- Key zeroing: AES keys cleared from memory on
close() - Bounded reads: All HTTP responses size-limited (1MB)
- Failsafe: SDK errors never crash the host application
Requirements
- Swift 5.9 or later
- macOS 13+ / iOS 16+
- LogFlux account with API key
No External Dependencies
Uses only Apple frameworks: CryptoKit, Security, Foundation, Network, Compression, os.log.
License
Elastic License 2.0 (ELv2) – free for all use except offering as a hosted or managed service to third parties.
Support
- Documentation: GitHub Repository
- Issues: GitHub Issues
Disclaimer
The Swift logo and trademarks are the property of Apple Inc. LogFlux is not affiliated with, endorsed by, or sponsored by Apple Inc. The Swift logo is used solely for identification purposes to indicate compatibility and integration capabilities.