Skip to content

Commit 064baa7

Browse files
committed
Document log collection & sending via email in README
1 parent a3766db commit 064baa7

File tree

1 file changed

+111
-6
lines changed

1 file changed

+111
-6
lines changed

README.md

Lines changed: 111 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -548,15 +548,120 @@ This precise grouping allows you to:
548548
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.
549549
550550
551-
## Attach Log File
551+
## User Feedback with Error Logs
552552
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. 😕
554554
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.
556556
557+
### The Power of System Logs
557558
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:
559560
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`:
577+
578+
```swift
579+
struct ContentView: View {
580+
@State private var showMailComposer = false
581+
582+
var body: some View {
583+
Form {
584+
// Your app content here
585+
586+
Button("Report a Problem") {
587+
showMailComposer = true
588+
}
589+
.mailComposer(
590+
isPresented: $showMailComposer,
591+
recipient: "support@yourapp.com",
592+
subject: "<AppName> Bug Report",
593+
messageBody: """
594+
Please describe what happened:
595+
596+
597+
598+
----------------------------------
599+
[Please do not remove the information below]
600+
601+
App version: \(Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "Unknown")
602+
Build: \(Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "Unknown")
603+
Device: \(UIDevice.current.model)
604+
iOS: \(UIDevice.current.systemVersion)
605+
""",
606+
attachments: [
607+
try? ErrorKit.logAttachment(ofLast: .minutes(30), minLevel: .notice)
608+
]
609+
)
610+
}
611+
}
612+
}
613+
```
614+
615+
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
561666
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

Comments
 (0)