-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b008cd1
commit a7232e9
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# 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 |