Browse Source

Migrate print() to os_log.

pull/92/head
Abhishek 4 years ago
parent
commit
b4913c6204
  1. 2
      Clocker/Clocker/LocationController.swift
  2. 6
      Clocker/ClockerUITests/FloatingWindowTests.swift
  3. 2
      Clocker/ClockerUITests/PreferencesTest.swift
  4. 2
      Clocker/Dependencies/Date Additions/TimeChunk.swift
  5. 8
      Clocker/Dependencies/Date Additions/TimePeriod.swift
  6. 2
      Clocker/Dependencies/Date Additions/TimePeriodChain.swift
  7. 14
      Clocker/Events and Reminders/CalendarHandler.swift
  8. 2
      Clocker/Events and Reminders/EventCenter.swift
  9. 2
      Clocker/Events and Reminders/RemindersHandler.swift
  10. 2
      Clocker/Menu Bar/MenubarHandler.swift
  11. 2
      Clocker/Menu Bar/StatusContainerView.swift
  12. 16
      Clocker/Menu Bar/StatusItemHandler.swift
  13. 2
      Clocker/Onboarding/FinalOnboardingViewController.swift
  14. 1
      Clocker/Onboarding/OnboardingParentViewController.swift
  15. 8
      Clocker/Onboarding/OnboardingSearchController.swift
  16. 8
      Clocker/Overall App/Logger.swift
  17. 8
      Clocker/Overall App/VersionUpdateHandler.swift
  18. 2
      Clocker/Panel/Data Layer/TimezoneData.swift
  19. 2
      Clocker/Panel/Data Layer/TimezoneDataOperations.swift
  20. 4
      Clocker/Panel/PanelController.swift
  21. 4
      Clocker/Panel/ParentPanelController.swift
  22. 2
      Clocker/Panel/UI/PanelTableView.swift
  23. 2
      Clocker/Preferences/Calendar/CalendarViewController.swift
  24. 4
      Clocker/Preferences/General/PreferencesDataSource.swift
  25. 12
      Clocker/Preferences/General/PreferencesViewController.swift
  26. 2
      Clocker/Preferences/Permissions/PermissionsViewController.swift

2
Clocker/Clocker/LocationController.swift

@ -111,6 +111,6 @@ extension LocationController: CLLocationManagerDelegate {
}
func locationManager(_: CLLocationManager, didFailWithError error: Error) {
print(error)
Logger.info(error.localizedDescription)
}
}

6
Clocker/ClockerUITests/FloatingWindowTests.swift

@ -25,11 +25,11 @@ class FloatingWindowTests: XCTestCase {
}
addUIInterruptionMonitor(withDescription: "Reminders Access") { (alert) -> Bool in
print("Interruption Handler called")
print(alert)
Logger.info("Interruption Handler called")
Logger.info(alert)
let alertButton = alert.buttons["OK"]
if alertButton.exists {
print("Okay button found")
Logger.info("Okay button found")
alertButton.tap()
return true
}

2
Clocker/ClockerUITests/PreferencesTest.swift

@ -392,7 +392,7 @@ extension XCTestCase {
let isHittable = NSPredicate(format: "exists == true", "")
let addExpectation = expectation(for: isHittable,
evaluatedWith: results.firstMatch) { () -> Bool in
print("Handler called")
Logger.info("Handler called")
return true
}

2
Clocker/Dependencies/Date Additions/TimeChunk.swift

@ -67,7 +67,7 @@ public struct TimeChunk {
*/
public func to(_ unit: TimeUnits) -> Int {
if months != 0 {
print("Months are not supported for conversion due to their uncertain number of days.")
Logger.info("Months are not supported for conversion due to their uncertain number of days.")
return 0
}
if unit == .seconds {

8
Clocker/Dependencies/Date Additions/TimePeriod.swift

@ -390,7 +390,7 @@ public extension TimePeriodProtocol {
end = end?.add(chunk)
case .center:
// Do not lengthen by TimeChunk at center
print("Mutation via chunk from center anchor is not supported.")
Logger.info("Mutation via chunk from center anchor is not supported.")
case .end:
beginning = beginning?.subtract(chunk)
}
@ -426,7 +426,7 @@ public extension TimePeriodProtocol {
end = end?.subtract(chunk)
case .center:
// Do not shorten by TimeChunk at center
print("Mutation via chunk from center anchor is not supported.")
Logger.info("Mutation via chunk from center anchor is not supported.")
case .end:
beginning = beginning?.add(chunk)
}
@ -561,7 +561,7 @@ open class TimePeriod: TimePeriodProtocol {
timePeriod.beginning = beginning
timePeriod.end = end?.add(chunk)
case .center:
print("Mutation via chunk from center anchor is not supported.")
Logger.info("Mutation via chunk from center anchor is not supported.")
case .end:
timePeriod.beginning = beginning?.add(-chunk)
timePeriod.end = end
@ -610,7 +610,7 @@ open class TimePeriod: TimePeriodProtocol {
timePeriod.beginning = beginning
timePeriod.end = end?.subtract(chunk)
case .center:
print("Mutation via chunk from center anchor is not supported.")
Logger.info("Mutation via chunk from center anchor is not supported.")
case .end:
timePeriod.beginning = beginning?.add(-chunk)
timePeriod.end = end

2
Clocker/Dependencies/Date Additions/TimePeriodChain.swift

@ -79,7 +79,7 @@ open class TimePeriodChain: TimePeriodGroup {
// Insert new period
periods.insert(period, at: index)
} else {
print("All TimePeriods in a TimePeriodChain must contain a defined start and end date")
Logger.info("All TimePeriods in a TimePeriodChain must contain a defined start and end date")
return
}

14
Clocker/Events and Reminders/CalendarHandler.swift

@ -66,7 +66,7 @@ extension EventCenter {
let timeForEventToStart = event.event.startDate.timeIntervalSinceNow / 60
if timeForEventToStart > 30 {
print("Our next event: \(event.event.title ?? "Error") starts in \(timeForEventToStart) mins")
Logger.info("Our next event: \(event.event.title ?? "Error") starts in \(timeForEventToStart) mins")
continue
}
@ -209,12 +209,12 @@ extension EventCenter {
}
}
print("Fetched filtered events for \(filteredEvents.count) days\n")
Logger.info("Fetched filtered events for \(filteredEvents.count) days\n")
return
}
print("Unable to filter events because user hasn't selected calendars")
Logger.info("Unable to filter events because user hasn't selected calendars")
}
func saveDefaultIdentifiersList() {
@ -224,7 +224,7 @@ extension EventCenter {
if !allCalendars.isEmpty {
UserDefaults.standard.set(allCalendars, forKey: CLSelectedCalendars)
print("Finished saving all calendar identifiers in default")
Logger.info("Finished saving all calendar identifiers in default")
self.filterEvents()
}
}
@ -259,7 +259,7 @@ extension EventCenter {
func fetchEvents(_ start: Int, _ end: Int) {
if calendarAccessDenied() || calendarAccessNotDetermined() {
print("Refetching aborted because we don't have permission!")
Logger.info("Refetching aborted because we don't have permission!")
return
}
@ -294,7 +294,7 @@ extension EventCenter {
while date.compare(final) == .orderedAscending {
guard var nextDate = autoupdatingCalendar.date(byAdding: Calendar.Component.day, value: 1, to: date) else {
print("Could not calculate end date")
Logger.info("Could not calculate end date")
return
}
nextDate = autoupdatingCalendar.startOfDay(for: nextDate)
@ -320,7 +320,7 @@ extension EventCenter {
eventsForDate = eventsForDateMapper
print("Fetched events for \(eventsForDate.count) days")
Logger.info("Fetched events for \(eventsForDate.count) days")
filterEvents()
}

2
Clocker/Events and Reminders/EventCenter.swift

@ -34,7 +34,7 @@ class EventCenter: NSObject {
}
private func refetchAll() {
print("\nRefetching events from the store")
Logger.info("\nRefetching events from the store")
eventsForDate = [:]
filteredEvents = [:]

2
Clocker/Events and Reminders/RemindersHandler.swift

@ -77,7 +77,7 @@ extension EventCenter {
try eventStore.save(reminderEvent, commit: true)
} catch {
Logger.log(object: ["Error": error.localizedDescription],
for: "Error saving reminder")
for: "Error saving reminder")
return false
}

2
Clocker/Menu Bar/MenubarHandler.swift

@ -45,7 +45,7 @@ class MenubarHandler: NSObject {
let timeForEventToStart = event.event.startDate.timeIntervalSinceNow / 60
if timeForEventToStart > 30 {
print("Our next event: \(event.event.title ?? "Error") starts in \(timeForEventToStart) mins")
Logger.info("Our next event: \(event.event.title ?? "Error") starts in \(timeForEventToStart) mins")
continue
}

2
Clocker/Menu Bar/StatusContainerView.swift

@ -171,7 +171,7 @@ class StatusContainerView: NSView {
}
if newWidth != frame.size.width, newWidth > frame.size.width + 2.0 {
print("Correcting our width to \(newWidth) and the previous width was \(frame.size.width)")
Logger.info("Correcting our width to \(newWidth) and the previous width was \(frame.size.width)")
frame = CGRect(x: frame.origin.x, y: frame.origin.y, width: newWidth, height: frame.size.height)
}
}

16
Clocker/Menu Bar/StatusItemHandler.swift

@ -56,7 +56,7 @@ class StatusItemHandler: NSObject {
setClockerIcon()
}
print("\nStatus Bar Current State changed: \(currentState)\n")
Logger.info("\nStatus Bar Current State changed: \(currentState)\n")
}
}
@ -191,7 +191,7 @@ class StatusItemHandler: NSObject {
menubarTimer?.tolerance = shouldDisplaySeconds ? 0.5 : 20
guard let runLoopTimer = menubarTimer else {
print("Timer is unexpectedly nil")
Logger.info("Timer is unexpectedly nil")
return
}
@ -230,12 +230,12 @@ class StatusItemHandler: NSObject {
} else if let minutes = components.minute {
components.minute = minutes + 1
} else {
print("Unable to create date components for the menubar timewr")
Logger.info("Unable to create date components for the menubar timewr")
return nil
}
guard let fireDate = nsCalendar.date(from: components) else {
print("Unable to form Fire Date")
Logger.info("Unable to form Fire Date")
return nil
}
@ -263,7 +263,7 @@ class StatusItemHandler: NSObject {
}
private func setupForStandardTextMode() {
print("Initializing menubar timer")
Logger.info("Initializing menubar timer")
// Let's invalidate the previous timer
menubarTimer?.invalidate()
@ -281,7 +281,7 @@ class StatusItemHandler: NSObject {
let menubarFavourites = DataStore.shared().menubarTimezones() ?? []
if menubarFavourites.isEmpty, DataStore.shared().shouldDisplay(.showMeetingInMenubar) == false {
print("Invalidating menubar timer!")
Logger.info("Invalidating menubar timer!")
invalidation()
@ -290,7 +290,7 @@ class StatusItemHandler: NSObject {
}
} else if sync {
print("Invalidating menubar timer for sync purposes!")
Logger.info("Invalidating menubar timer for sync purposes!")
invalidation()
@ -299,7 +299,7 @@ class StatusItemHandler: NSObject {
}
} else {
print("Not stopping menubar timer!")
Logger.info("Not stopping menubar timer!")
}
}

2
Clocker/Onboarding/FinalOnboardingViewController.swift

@ -98,7 +98,7 @@ class FinalOnboardingViewController: NSViewController {
private func extraData() -> [String: String]? {
guard let validEmail = emailValidator.validate(field: emailTextField) else {
print("Not sending up email because it was invalid")
Logger.info("Not sending up email because it was invalid")
return nil
}

1
Clocker/Onboarding/OnboardingParentViewController.swift

@ -310,7 +310,6 @@ class OnboardingParentViewController: NSViewController {
func logExitPoint() {
let currentViewController = currentController()
print(currentViewController)
Logger.log(object: currentViewController, for: "Onboarding Process Exit")
}

8
Clocker/Onboarding/OnboardingSearchController.swift

@ -136,7 +136,7 @@ class OnboardingSearchController: NSViewController {
let decodedObject = try jsonDecoder.decode(Timezone.self, from: data)
return decodedObject
} catch {
print("decodedObject error: \n\(error)")
Logger.info("decodedObject error: \n\(error)")
return nil
}
}
@ -190,7 +190,7 @@ class OnboardingSearchController: NSViewController {
self.undoButton.isHidden = false
Logger.log(object: ["Place Name": filteredAddress],
for: "Added Timezone while Onboarding")
for: "Added Timezone while Onboarding")
}
// Cleanup.
@ -364,7 +364,7 @@ class OnboardingSearchController: NSViewController {
let decodedObject = try jsonDecoder.decode(SearchResult.self, from: data)
return decodedObject
} catch {
print("decodedObject error: \n\(error)")
Logger.info("decodedObject error: \n\(error)")
return nil
}
}
@ -453,7 +453,7 @@ extension OnboardingSearchController: NSSearchFieldDelegate {
return false
}
print("Not Handled")
Logger.info("Not Handled")
// return true if the action was handled; otherwise false
return false
}

8
Clocker/Overall App/Logger.swift

@ -7,7 +7,13 @@ import os.signpost
class Logger: NSObject {
class func log(object annotations: [String: Any]?, for event: NSString) {
if #available(OSX 10.14, *) {
os_log(.info, "[%@] - [%@]", event, annotations ?? [:])
os_log(.default, "[%@] - [%@]", event, annotations ?? [:])
}
}
class func info(_ message: String) {
if #available(OSX 10.14, *) {
os_log(.info, "[%@]", message)
}
}
}

8
Clocker/Overall App/VersionUpdateHandler.swift

@ -96,7 +96,7 @@ class VersionUpdateHandler: NSObject {
}
guard let appStoreId = appStoreID() else {
print("No App Store ID was found for Clocker")
Logger.info("No App Store ID was found for Clocker")
return URL(string: "")!
}
@ -197,7 +197,7 @@ class VersionUpdateHandler: NSObject {
if checkAtLaunch {
checkIfNewVersion()
} else if verboseLogging {
print("iVersion will not check for updatess because checkAtLaunch option is disabled")
Logger.info("iVersion will not check for updatess because checkAtLaunch option is disabled")
}
}
@ -311,9 +311,9 @@ class VersionUpdateHandler: NSObject {
if remoteVersionsDict.count <= 0 {
if downloadError != nil {
print("Update Check Failed because of \(downloadError!.localizedDescription)")
Logger.info("Update Check Failed because of \(downloadError!.localizedDescription)")
} else {
print("Version Update Check because an unknown error occurred")
Logger.info("Version Update Check because an unknown error occurred")
}
}
return

2
Clocker/Panel/Data Layer/TimezoneData.swift

@ -231,7 +231,7 @@ class TimezoneData: NSObject, NSCoding {
let old = NSKeyedUnarchiver.unarchiveObject(with: timezone)
if let oldModel = old as? CLTimezoneData {
// Convert it to new model and add it
print("We're still using old Objective-C models")
Logger.info("We're still using old Objective-C models")
let newTimezone = TimezoneData(with: oldModel)
newModels.append(newTimezone)
} else if let newModel = old as? TimezoneData {

2
Clocker/Panel/Data Layer/TimezoneDataOperations.swift

@ -79,7 +79,7 @@ extension TimezoneDataOperations {
let timeForEventToStart = event.event.startDate.timeIntervalSinceNow / 60
if timeForEventToStart > 30 {
print("Our next event: \(event.event.title ?? "Error") starts in \(timeForEventToStart) mins")
Logger.info("Our next event: \(event.event.title ?? "Error") starts in \(timeForEventToStart) mins")
continue
}

4
Clocker/Panel/PanelController.swift

@ -239,7 +239,7 @@ class PanelController: ParentPanelController {
}
private func startTimer() {
print("Start timer called")
Logger.info("Start timer called")
parentTimer = Repeater(interval: .seconds(1), mode: .infinite) { _ in
OperationQueue.main.addOperation {
@ -254,7 +254,7 @@ class PanelController: ParentPanelController {
if count >= 1 || DataStore.shared().shouldDisplay(.showMeetingInMenubar) {
if let delegate = NSApplication.shared.delegate as? AppDelegate {
print("\nWe will be invalidating the menubar timer as we want the parent timer to take care of both panel and menubar ")
Logger.info("\nWe will be invalidating the menubar timer as we want the parent timer to take care of both panel and menubar ")
delegate.invalidateMenubarTimer(false)
}

4
Clocker/Panel/ParentPanelController.swift

@ -1025,7 +1025,7 @@ extension ParentPanelController: NSPopoverDelegate {
extension ParentPanelController: NSSharingServicePickerDelegate {
func sharingServicePicker(_: NSSharingServicePicker, delegateFor sharingService: NSSharingService) -> NSSharingServiceDelegate? {
Logger.log(object: ["Service Title": sharingService.title],
for: "Sharing Service Executed")
for: "Sharing Service Executed")
return self as? NSSharingServiceDelegate
}
}
@ -1042,6 +1042,6 @@ extension ParentPanelController: NSCollectionViewDataSource, NSCollectionViewDel
}
func collectionView(_: NSCollectionView, didSelectItemsAt indexPaths: Set<IndexPath>) {
Swift.print("Did Select Item at \(indexPaths.description)")
Logger.info("Did Select Item at \(indexPaths.description)")
}
}

2
Clocker/Panel/UI/PanelTableView.swift

@ -90,7 +90,7 @@ class PanelTableView: NSTableView {
private func evaluateForHighlight(at point: NSPoint) {
if enableHover == false {
print("Unable to show hover button because window is occluded!")
Logger.info("Unable to show hover button because window is occluded!")
return
}

2
Clocker/Preferences/Calendar/CalendarViewController.swift

@ -146,7 +146,7 @@ class CalendarViewController: ParentViewController {
if sender.selectedSegment == 0 {
if let isValid = statusItemHandler.menubarTimer?.isValid, isValid == true {
print("Timer is already in progress")
Logger.info("Timer is already in progress")
updateStatusItem()
return
}

4
Clocker/Preferences/General/PreferencesDataSource.swift

@ -161,7 +161,7 @@ extension PreferencesDataSource: NSTableViewDataSource {
"Old Label": dataObject.customLabel ?? "Error",
"New Label": formattedValue,
],
for: "Custom Label Changed")
for: "Custom Label Changed")
dataObject.setLabel(formattedValue)
@ -174,7 +174,7 @@ extension PreferencesDataSource: NSTableViewDataSource {
"Selected Timezone Count": selectedTimezones.count,
"Current Row": row,
],
for: "Error in selected row count")
for: "Error in selected row count")
}
}

12
Clocker/Preferences/General/PreferencesViewController.swift

@ -327,7 +327,7 @@ extension PreferencesViewController: NSTableViewDataSource, NSTableViewDelegate
private func _unfavourite(_ dataObject: TimezoneData) {
Logger.log(object: ["label": dataObject.customLabel ?? "Error"],
for: "favouriteRemoved")
for: "favouriteRemoved")
if let appDelegate = NSApplication.shared.delegate as? AppDelegate,
let menubarFavourites = DataStore.shared().menubarTimezones(),
@ -420,7 +420,7 @@ extension PreferencesViewController {
self.placeholderLabel.placeholderString = "Searching for \(searchString)"
print(self.placeholderLabel.placeholderString ?? "")
Logger.info(self.placeholderLabel.placeholderString ?? "")
self.dataTask = NetworkManager.task(with: self.generateSearchURL(),
completionHandler: { [weak self] response, error in
@ -474,7 +474,7 @@ extension PreferencesViewController {
return false
}
print(searchResultsDataSource.timezoneFilteredArray)
Logger.info(searchResultsDataSource.timezoneFilteredArray.debugDescription)
}
private func generateSearchURL() -> String {
@ -528,7 +528,7 @@ extension PreferencesViewController {
private func reloadSearchResults() {
if searchResultsDataSource.calculateChangesets() {
print("Reloading Search Results")
Logger.info("Reloading Search Results")
availableTimezoneTableView.reloadData()
}
}
@ -540,7 +540,7 @@ extension PreferencesViewController {
let decodedObject = try jsonDecoder.decode(SearchResult.self, from: data)
return decodedObject
} catch {
print("decodedObject error: \n\(error)")
Logger.info("decodedObject error: \n\(error)")
return nil
}
}
@ -552,7 +552,7 @@ extension PreferencesViewController {
let decodedObject = try jsonDecoder.decode(Timezone.self, from: data)
return decodedObject
} catch {
print("decodedObject error: \n\(error)")
Logger.info("decodedObject error: \n\(error)")
return nil
}
}

2
Clocker/Preferences/Permissions/PermissionsViewController.swift

@ -149,7 +149,7 @@ class PermissionsViewController: ParentViewController {
}
} else {
Logger.log(object: ["Reminder Access Not Granted": "YES"],
for: "Reminder Access Not Granted")
for: "Reminder Access Not Granted")
}
})
} else if eventCenter.calendarAccessGranted() {

Loading…
Cancel
Save