https://github.com/areroketahi/swift-log-data
A swift-log backend which using SwiftData to store log.
https://github.com/areroketahi/swift-log-data
logging swift swift-6 swift-log swift-package swiftui
Last synced: 2 months ago
JSON representation
A swift-log backend which using SwiftData to store log.
- Host: GitHub
- URL: https://github.com/areroketahi/swift-log-data
- Owner: AreroKetahi
- Created: 2024-12-22T23:38:57.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-23T02:07:14.000Z (over 1 year ago)
- Last Synced: 2025-11-18T09:24:06.208Z (7 months ago)
- Topics: logging, swift, swift-6, swift-log, swift-package, swiftui
- Language: Swift
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# swift-log-data
A swift-log backend which using SwiftData to store log.
## Quick Start - SwiftUI
1. Register the model container in the scene that you may logging.
Here is an example that regsiter the model in to the main scene.
```swift
import DataLogger
@main
struct Example_App: App {
var body: some Scene {
WindowGroup {
ContentView()
}
.logContainer()
}
}
```
2. Bootstrap the logger.
```swift
import Logging
// Initializer in Example_App
init() {
LoggingSystem.bootstrap(DataLogger.init)
}
```
3. Use the swift-log API for logging. For more details, please check [swift-log Github Repo](https://github.com/apple/swift-log).
## Read the logs
If you are using SwiftUI, you can use environmental `logActor` to access the logging actor.
```swift
@Environment(\.logActor) var logActor
func getLogs() async throws -> [Log] {
try await logActor.fetch()
}
```
The model store of logs stored in /Container/Library/Logs