Better TimelineLikeController logging

This commit is contained in:
Shadowfacts 2023-05-11 15:11:43 -04:00
parent db7c183d06
commit d003098146
5 changed files with 11 additions and 9 deletions

View File

@ -116,7 +116,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let objClazz = clazz as AnyObject as? NSObjectProtocol, let objClazz = clazz as AnyObject as? NSObjectProtocol,
objClazz.responds(to: Selector(("id"))), objClazz.responds(to: Selector(("id"))),
let id = objClazz.perform(Selector(("id"))).takeUnretainedValue() as? String { 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)")
} }
} }

View File

@ -33,7 +33,7 @@ class NotificationsCollectionViewController: UIViewController, TimelineLikeColle
super.init(nibName: nil, bundle: nil) 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")) addKeyCommand(MenuController.refreshCommand(discoverabilityTitle: "Refresh Notifications"))
} }

View File

@ -45,7 +45,7 @@ class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionVie
super.init(nibName: nil, bundle: nil) 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")) addKeyCommand(MenuController.refreshCommand(discoverabilityTitle: "Refresh Profile"))
} }

View File

@ -64,7 +64,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
super.init(nibName: nil, bundle: nil) 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 self.navigationItem.title = timeline.title
addKeyCommand(MenuController.refreshCommand(discoverabilityTitle: "Refresh Timeline")) addKeyCommand(MenuController.refreshCommand(discoverabilityTitle: "Refresh Timeline"))

View File

@ -40,19 +40,21 @@ private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category:
class TimelineLikeController<Item: Sendable> { class TimelineLikeController<Item: Sendable> {
private unowned var delegate: any TimelineLikeControllerDelegate<Item> private unowned var delegate: any TimelineLikeControllerDelegate<Item>
private let ownerType: String
private(set) var state = State.notLoadedInitial { private(set) var state = State.notLoadedInitial {
willSet { willSet {
guard state.canTransition(to: newValue) else { 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)") 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<Item>) { init(delegate: any TimelineLikeControllerDelegate<Item>, ownerType: String) {
self.delegate = delegate self.delegate = delegate
self.ownerType = ownerType
} }
func loadInitial() async { func loadInitial() async {
@ -171,7 +173,7 @@ class TimelineLikeController<Item: Sendable> {
private func emit(event: Event) async { private func emit(event: Event) async {
guard state.canEmit(event: event) else { 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)") fatalError("State \(state) cannot emit event: \(event)")
} }
switch event { switch event {
@ -324,7 +326,7 @@ class TimelineLikeController<Item: Sendable> {
case .loadAllError(let error, let token): case .loadAllError(let error, let token):
return "loadAllError(\(error), \(token))" return "loadAllError(\(error), \(token))"
case .replaceAllItems(_, let token): case .replaceAllItems(_, let token):
return "replcaeAllItems(<omitted>, \(token))" return "replaceAllItems(<omitted>, \(token))"
case .loadNewerError(let error, let token): case .loadNewerError(let error, let token):
return "loadNewerError(\(error), \(token))" return "loadNewerError(\(error), \(token))"
case .prependItems(_, let token): case .prependItems(_, let token):