You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+111-6Lines changed: 111 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -548,15 +548,120 @@ This precise grouping allows you to:
548
548
ErrorKit's debugging tools transform error handling from a black box into a transparent system. By combining `errorChainDescription` for debugging with `groupingID` for analytics, you get deep insight into error flows while maintaining the ability to track and prioritize issues effectively. This is particularly powerful when combined with ErrorKit's `Catching` protocol, creating a comprehensive system for error handling, debugging, and monitoring.
549
549
550
550
551
-
## Attach Log File
551
+
## User Feedback with Error Logs
552
552
553
-
ErrorKit makes it super easy to attach a log file with relevant console output data to user bug reports.
553
+
When users encounter issues in your app, getting enough context to diagnose the problem can be challenging. Users rarely know what information you need, and reproducing issues without logs is often impossible. 😕
554
554
555
-
TODO: continue here
555
+
ErrorKit makes it simple to add diagnostic log collection to your app, providing crucial context for bug reports and support requests.
556
556
557
+
### The Power of System Logs
557
558
558
-
## Life Error Analytics
559
+
ErrorKit leverages Apple's unified logging system (`OSLog`/`Logger`) to collect valuable diagnostic information. If you're not already using structured logging, here's a quick primer:
559
560
560
-
ErrorKit comes with hooks that make it easy to connect the reporting of errors to analytics service so you can find out which errors your users are confronted with most, without them having to contact you! This is great to proactively track issues in your app, track how they're evolving after you make a bug fix release or generally to make decisions on what to fix first!
561
+
```swift
562
+
import OSLog
563
+
564
+
// Log at appropriate levels
565
+
Logger().debug("Detailed connection info: \(details)") // Development debugging
566
+
Logger().info("User tapped on \(button)") // General information
567
+
Logger().notice("Successfully loaded user profile") // Important events
568
+
Logger().error("Failed to parse server response") // Errors that should be fixed
569
+
Logger().fault("Database corruption detected") // Critical system failures
570
+
```
571
+
572
+
ErrorKit can collect these logs based on level, giving you control over how much detail to include in reports. 3rd-party frameworks that also use Apple's unified logging system will be included so you get a full picture of what happened in your app, not just what you logged yourself.
573
+
574
+
### Creating a Feedback Button with Automatic Log Collection
575
+
576
+
The easiest way to implement a support system is using the `.mailComposer` SwiftUI modifier combined with `logAttachment`:
This creates a simple "Report a Problem" button that:
616
+
1. Opens a pre-filled email composer
617
+
2. Includes useful device and app information
618
+
3. Automatically attaches recent system logs
619
+
4. Provides space for the user to describe the issue
620
+
621
+
The above is just an example, feel free to adjust it to your needs and include any additional info needed.
622
+
623
+
### Alternative Methods for More Control
624
+
625
+
If you need more control over log handling, ErrorKit offers two additional approaches:
626
+
627
+
#### 1. Getting Log Data Directly
628
+
629
+
For sending logs to your own backend or processing them in-app:
630
+
631
+
```swift
632
+
let logData = try ErrorKit.loggedData(
633
+
ofLast: .minutes(10),
634
+
minLevel: .notice
635
+
)
636
+
637
+
// Use the data with your custom reporting system
638
+
analyticsService.sendLogs(data: logData)
639
+
```
640
+
641
+
#### 2. Exporting to a Temporary File
642
+
643
+
For sharing logs via other mechanisms:
644
+
645
+
```swift
646
+
let logFileURL = try ErrorKit.exportLogFile(
647
+
ofLast: .hours(1),
648
+
minLevel: .error
649
+
)
650
+
651
+
// Share the log file
652
+
let activityVC = UIActivityViewController(
653
+
activityItems: [logFileURL],
654
+
applicationActivities: nil
655
+
)
656
+
present(activityVC, animated: true)
657
+
```
658
+
659
+
### Benefits of Automatic Log Collection
660
+
661
+
- **Better bug reports**: Get the context you need without asking users for technical details
662
+
- **Faster issue resolution**: See exactly what happened leading up to the problem
663
+
- **Lower support burden**: Reduce back-and-forth communications with users
664
+
- **User satisfaction**: Demonstrate that you take their problems seriously
665
+
- **Developer sanity**: Stop trying to reproduce issues with insufficient information
561
666
562
-
TODO: continue here
667
+
By implementing a feedback button with automatic log collection, you transform the error reporting experience for both users and developers. Users can report issues with a single tap, and you get the diagnostic information you need to fix problems quickly.
0 commit comments