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
+120Lines changed: 120 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,7 @@ ErrorKit makes error handling in Swift more intuitive. It reduces boilerplate co
10
10
-[Typed Throws for System Functions](#typed-throws-for-system-functions)
11
11
-[Error Nesting with Catching](#error-nesting-with-catching)
12
12
-[Error Chain Debugging](#error-chain-debugging)
13
+
-[User Feedback with Error Logs](#user-feedback-with-error-logs)
13
14
14
15
## The Problem with Swift's Error Protocol
15
16
@@ -544,3 +545,122 @@ This precise grouping allows you to:
544
545
### Summary
545
546
546
547
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.
548
+
549
+
550
+
## User Feedback with Error Logs
551
+
552
+
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. 😕
553
+
554
+
ErrorKit makes it simple to add diagnostic log collection to your app, providing crucial context for bug reports and support requests.
555
+
556
+
### The Power of System Logs
557
+
558
+
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
+
```swift
561
+
import OSLog
562
+
563
+
// Log at appropriate levels
564
+
Logger().debug("Detailed connection info: \(details)") // Development debugging
565
+
Logger().info("User tapped on \(button)") // General information
566
+
Logger().notice("Successfully loaded user profile") // Important events
567
+
Logger().error("Failed to parse server response") // Errors that should be fixed
568
+
Logger().fault("Database corruption detected") // Critical system failures
569
+
```
570
+
571
+
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.
572
+
573
+
### Creating a Feedback Button with Automatic Log Collection
574
+
575
+
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:
615
+
1. Opens a pre-filled email composer
616
+
2. Includes useful device and app information
617
+
3. Automatically attaches recent system logs
618
+
4. Provides space for the user to describe the issue
619
+
620
+
The above is just an example, feel free to adjust it to your needs and include any additional info needed.
621
+
622
+
### Alternative Methods for More Control
623
+
624
+
If you need more control over log handling, ErrorKit offers two additional approaches:
625
+
626
+
#### 1. Getting Log Data Directly
627
+
628
+
For sending logs to your own backend or processing them in-app:
629
+
630
+
```swift
631
+
let logData = try ErrorKit.loggedData(
632
+
ofLast: .minutes(10),
633
+
minLevel: .notice
634
+
)
635
+
636
+
// Use the data with your custom reporting system
637
+
analyticsService.sendLogs(data: logData)
638
+
```
639
+
640
+
#### 2. Exporting to a Temporary File
641
+
642
+
For sharing logs via other mechanisms:
643
+
644
+
```swift
645
+
let logFileURL = try ErrorKit.exportLogFile(
646
+
ofLast: .hours(1),
647
+
minLevel: .error
648
+
)
649
+
650
+
// Share the log file
651
+
let activityVC = UIActivityViewController(
652
+
activityItems: [logFileURL],
653
+
applicationActivities: nil
654
+
)
655
+
present(activityVC, animated: true)
656
+
```
657
+
658
+
### Benefits of Automatic Log Collection
659
+
660
+
- **Better bug reports**: Get the context you need without asking users for technical details
661
+
- **Faster issue resolution**: See exactly what happened leading up to the problem
662
+
- **Lower support burden**: Reduce back-and-forth communications with users
663
+
- **User satisfaction**: Demonstrate that you take their problems seriously
664
+
- **Developer sanity**: Stop trying to reproduce issues with insufficient information
665
+
666
+
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.
defaultValue:"The operation could not be started because a required component failed to initialize: \(dependency). Please restart the application or contact support.",
defaultValue:"The operation could not be started because a required component failed to initialize: \(dependency). Please restart the application or contact support."
0 commit comments