From d00309814663be9416fb5a5696c07f41bff2f31d Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 11 May 2023 15:11:43 -0400 Subject: [PATCH] Better TimelineLikeController logging --- Tusker/AppDelegate.swift | 2 +- .../NotificationsCollectionViewController.swift | 2 +- .../Profile/ProfileStatusesViewController.swift | 2 +- Tusker/Screens/Timeline/TimelineViewController.swift | 2 +- Tusker/TimelineLikeController.swift | 12 +++++++----- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Tusker/AppDelegate.swift b/Tusker/AppDelegate.swift index 9bd2673b..1751e9e7 100644 --- a/Tusker/AppDelegate.swift +++ b/Tusker/AppDelegate.swift @@ -116,7 +116,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { let objClazz = clazz as AnyObject as? NSObjectProtocol, objClazz.responds(to: Selector(("id"))), let id = objClazz.perform(Selector(("id"))).takeUnretainedValue() as? String { - logger.info("Initialized Sentry with installation/user ID: \(id)") + logger.info("Initialized Sentry with installation/user ID: \(id, privacy: .public)") } } diff --git a/Tusker/Screens/Notifications/NotificationsCollectionViewController.swift b/Tusker/Screens/Notifications/NotificationsCollectionViewController.swift index 051eafb6..7f92a01d 100644 --- a/Tusker/Screens/Notifications/NotificationsCollectionViewController.swift +++ b/Tusker/Screens/Notifications/NotificationsCollectionViewController.swift @@ -33,7 +33,7 @@ class NotificationsCollectionViewController: UIViewController, TimelineLikeColle super.init(nibName: nil, bundle: nil) - self.controller = TimelineLikeController(delegate: self) + self.controller = TimelineLikeController(delegate: self, ownerType: String(describing: self)) addKeyCommand(MenuController.refreshCommand(discoverabilityTitle: "Refresh Notifications")) } diff --git a/Tusker/Screens/Profile/ProfileStatusesViewController.swift b/Tusker/Screens/Profile/ProfileStatusesViewController.swift index a1afd5c3..8972dece 100644 --- a/Tusker/Screens/Profile/ProfileStatusesViewController.swift +++ b/Tusker/Screens/Profile/ProfileStatusesViewController.swift @@ -45,7 +45,7 @@ class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionVie super.init(nibName: nil, bundle: nil) - self.controller = TimelineLikeController(delegate: self) + self.controller = TimelineLikeController(delegate: self, ownerType: String(describing: self)) addKeyCommand(MenuController.refreshCommand(discoverabilityTitle: "Refresh Profile")) } diff --git a/Tusker/Screens/Timeline/TimelineViewController.swift b/Tusker/Screens/Timeline/TimelineViewController.swift index 538fde9a..8587dcfe 100644 --- a/Tusker/Screens/Timeline/TimelineViewController.swift +++ b/Tusker/Screens/Timeline/TimelineViewController.swift @@ -64,7 +64,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro super.init(nibName: nil, bundle: nil) - self.controller = TimelineLikeController(delegate: self) + self.controller = TimelineLikeController(delegate: self, ownerType: String(describing: self)) self.navigationItem.title = timeline.title addKeyCommand(MenuController.refreshCommand(discoverabilityTitle: "Refresh Timeline")) diff --git a/Tusker/TimelineLikeController.swift b/Tusker/TimelineLikeController.swift index ea6171a9..a11aca77 100644 --- a/Tusker/TimelineLikeController.swift +++ b/Tusker/TimelineLikeController.swift @@ -40,19 +40,21 @@ private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: class TimelineLikeController { private unowned var delegate: any TimelineLikeControllerDelegate + private let ownerType: String private(set) var state = State.notLoadedInitial { willSet { guard state.canTransition(to: newValue) else { - logger.error("State \(self.state.debugDescription, privacy: .public) cannot transition to \(newValue.debugDescription, privacy: .public)") + logger.error("\(self.ownerType, privacy: .public) State \(self.state.debugDescription, privacy: .public) cannot transition to \(newValue.debugDescription, privacy: .public)") fatalError("State \(state) cannot transition to \(newValue)") } - logger.debug("State: \(self.state.debugDescription, privacy: .public) -> \(newValue.debugDescription, privacy: .public)") + logger.debug("\(self.ownerType, privacy: .public) State: \(self.state.debugDescription, privacy: .public) -> \(newValue.debugDescription, privacy: .public)") } } - init(delegate: any TimelineLikeControllerDelegate) { + init(delegate: any TimelineLikeControllerDelegate, ownerType: String) { self.delegate = delegate + self.ownerType = ownerType } func loadInitial() async { @@ -171,7 +173,7 @@ class TimelineLikeController { private func emit(event: Event) async { guard state.canEmit(event: event) else { - logger.error("State \(self.state.debugDescription, privacy: .public) cannot emit event: \(event.debugDescription, privacy: .public)") + logger.error("\(self.ownerType, privacy: .public) State \(self.state.debugDescription, privacy: .public) cannot emit event: \(event.debugDescription, privacy: .public)") fatalError("State \(state) cannot emit event: \(event)") } switch event { @@ -324,7 +326,7 @@ class TimelineLikeController { case .loadAllError(let error, let token): return "loadAllError(\(error), \(token))" case .replaceAllItems(_, let token): - return "replcaeAllItems(, \(token))" + return "replaceAllItems(, \(token))" case .loadNewerError(let error, let token): return "loadNewerError(\(error), \(token))" case .prependItems(_, let token):