CollectionIssueReporter.swift 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import Foundation
  2. import Swinject
  3. protocol GroupedIssueReporter: IssueReporter {
  4. func add(reporters: [IssueReporter])
  5. func remove(reporter: IssueReporter)
  6. }
  7. final class CollectionIssueReporter: GroupedIssueReporter {
  8. private let reportersLock = NSRecursiveLock(label: "CollectionIssueReporter.reportersLock")
  9. private var reporters: [IssueReporter] = []
  10. func setup() {
  11. reportersLock.perform {
  12. reporters.forEach { $0.setup() }
  13. }
  14. }
  15. func setUserIdentifier(_ identifier: String?) {
  16. reportersLock.perform {
  17. reporters.forEach { $0.setUserIdentifier(identifier) }
  18. }
  19. }
  20. func reportNonFatalIssue(withName name: String, attributes: [String: String]) {
  21. reportersLock.perform {
  22. reporters.forEach { $0.reportNonFatalIssue(withName: name, attributes: attributes) }
  23. }
  24. }
  25. func reportNonFatalIssue(withError error: NSError) {
  26. reportersLock.perform {
  27. reporters.forEach { $0.reportNonFatalIssue(withError: error) }
  28. }
  29. }
  30. func log(_ category: String, _ message: String, file: String, function: String, line: UInt) {
  31. reportersLock.perform {
  32. reporters.forEach { $0.log(category, message, file: file, function: function, line: line) }
  33. }
  34. }
  35. func add(reporters: [IssueReporter]) {
  36. reportersLock.perform {
  37. self.reporters.append(contentsOf: reporters)
  38. }
  39. }
  40. func remove(reporter: IssueReporter) {
  41. reportersLock.perform {
  42. reporters.removeAll { $0 === reporter }
  43. }
  44. }
  45. }