-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add highlights summary to bug report attachment #124
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,12 +43,14 @@ public final class LogStoreAttachmentGenerator: NSObject { | |
/// - parameter messageFormatter: The formatter used to format messages in the logs attachment. | ||
/// - parameter includeLatestScreenshot: Whether an attachment should be generated for the last screenshot in the | ||
/// log store, if one exists. | ||
/// - parameter numberOfErrorsInHighlights: The number of errors to include in the highlights for the log store. | ||
/// - parameter completionQueue: The queue on which the completion should be called. | ||
/// - parameter completion: The completion to be called once the attachments have been generated. | ||
public static func attachments( | ||
for logStore: ARKLogStore, | ||
messageFormatter: ARKLogFormatter = ARKDefaultLogFormatter(), | ||
includeLatestScreenshot: Bool, | ||
numberOfErrorsInHighlights: UInt = 3, | ||
completionQueue: DispatchQueue, | ||
completion: @escaping (Attachments) -> Void | ||
) { | ||
|
@@ -63,7 +65,8 @@ public final class LogStoreAttachmentGenerator: NSObject { | |
let logsAttachment = attachment( | ||
for: logMessages, | ||
using: messageFormatter, | ||
logStoreName: logStore.name | ||
logStoreName: logStore.name, | ||
numberOfErrorsInHighlights: numberOfErrorsInHighlights | ||
) | ||
|
||
completionQueue.async { | ||
|
@@ -107,11 +110,13 @@ public final class LogStoreAttachmentGenerator: NSObject { | |
/// - parameter logMessages: The log messages to be included in the attachment. | ||
/// - parameter logFormatter: The formatter with which to format the log messages. | ||
/// - parameter logStoreName: The name of the log store from which the logs were collected. | ||
@objc(attachmentForLogMessages:usingLogFormatter:logStoreName:) | ||
/// - parameter numberOfErrorsInHighlights: The number of errors to include in the highlights for the log store. | ||
@objc(attachmentForLogMessages:usingLogFormatter:logStoreName:numberOfErrorsInHighlights:) | ||
public static func attachment( | ||
for logMessages: [ARKLogMessage], | ||
using logFormatter: ARKLogFormatter = ARKDefaultLogFormatter(), | ||
logStoreName: String? | ||
logStoreName: String?, | ||
numberOfErrorsInHighlights: UInt = 3 | ||
) -> ARKBugReportAttachment? { | ||
guard !logMessages.isEmpty else { | ||
return nil | ||
|
@@ -124,10 +129,19 @@ public final class LogStoreAttachmentGenerator: NSObject { | |
|
||
let fileName = logsFileName(for: logStoreName, fileType: "txt") | ||
|
||
let recentErrorSummary = logMessages | ||
.lazy | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Um, I'll be lazy: is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the |
||
.reversed() | ||
.filter { $0.type == .error } | ||
.prefix(Int(numberOfErrorsInHighlights)) | ||
.map { $0.text } | ||
.joined(separator: "\n") | ||
|
||
return ARKBugReportAttachment( | ||
fileName: fileName, | ||
data: formattedLogData, | ||
dataMIMEType: "text/plain" | ||
dataMIMEType: "text/plain", | ||
highlightsSummary: recentErrorSummary.isEmpty ? nil : recentErrorSummary | ||
) | ||
} | ||
|
||
|
@@ -138,11 +152,12 @@ public final class LogStoreAttachmentGenerator: NSObject { | |
/// - parameter logFormatter: The formatter with which to format the log messages. | ||
/// - parameter logStoreName: The name of the log store from which the logs were collected. | ||
/// - parameter completion: A completion handler that retuns void, and is passed an optional attachment. | ||
@objc(attachmentForLogMessages:usingLogFormatter:logStoreName:completion:) | ||
@objc(attachmentForLogMessages:usingLogFormatter:logStoreName:numberOfErrorsInHighlights:completion:) | ||
public static func attachment( | ||
for logMessages: [ARKLogMessage], | ||
using logFormatter: ARKLogFormatter = ARKDefaultLogFormatter(), | ||
logStoreName: String?, | ||
numberOfErrorsInHighlights: UInt = 3, | ||
completion: @escaping @convention(block)(ARKBugReportAttachment?) -> Void | ||
) -> Void { | ||
guard !logMessages.isEmpty else { | ||
|
@@ -160,10 +175,19 @@ public final class LogStoreAttachmentGenerator: NSObject { | |
|
||
let fileName = logsFileName(for: logStoreName, fileType: "txt") | ||
|
||
let recentErrorSummary = logMessages | ||
.lazy | ||
.reversed() | ||
.filter { $0.type == .error } | ||
.prefix(Int(numberOfErrorsInHighlights)) | ||
.map { $0.text } | ||
.joined(separator: "\n") | ||
|
||
let attachment = ARKBugReportAttachment( | ||
fileName: fileName, | ||
data: formattedLogData, | ||
dataMIMEType: "text/plain" | ||
dataMIMEType: "text/plain", | ||
highlightsSummary: recentErrorSummary.isEmpty ? nil : recentErrorSummary | ||
) | ||
|
||
DispatchQueue.main.async { | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change for Aardvark. This one would be fairly easy to work around (by creating a separate method, rather than adding a parameter with a default value). I could go either way on this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2¢ For such a small change, I think the workaround is preferable.