Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/0xleif/swiftuilogger
Logging to a SwiftUI View
https://github.com/0xleif/swiftuilogger
logging swiftui
Last synced: 3 months ago
JSON representation
Logging to a SwiftUI View
- Host: GitHub
- URL: https://github.com/0xleif/swiftuilogger
- Owner: 0xLeif
- License: mit
- Created: 2022-10-13T02:58:07.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-29T17:07:11.000Z (about 1 year ago)
- Last Synced: 2024-05-02T03:09:18.472Z (9 months ago)
- Topics: logging, swiftui
- Language: Swift
- Homepage:
- Size: 27.3 KB
- Stars: 6
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SwiftUILogger
*Logging to a SwiftUI View*
## What is SwiftUILogger?
SwiftUILogger allows you to log events by reference. Then you can display all the events using the LoggerView and passing the logger into the initalizer.
## Why use SwiftUILogger?
SwiftUILogger can be used while developing and testing your application to quickly see the debug logs without needing to be attached to LLDB session or Xcode.
## Example Usage
```swift
import SwiftUI
import SwiftUILoggerlet logger = SwiftUILogger(name: "Demo")
@main
struct SwiftUILogger_DemoApp: App {
@State private var isPresentedLogger: Bool = falsevar body: some Scene {
WindowGroup {
NavigationStack {
ContentView()
.sheet(isPresented: $isPresentedLogger) {
LoggerView(logger: logger)
}
.toolbar {
Button(
action: { isPresentedLogger.toggle() },
label: { Image(systemName: "ladybug") }
)
}
}
}
}
}// MARK: - ContentView
struct ContentView: View {
init() {
logger.log(level: .info, message: "init")
}var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
Text("Hello, world!")
}
.padding()
.onAppear {
logger.log(level: .info, message: "onAppear")
}
}
}```