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/Menu Bar/MenubarHandler.swift
  10. 2
      Clocker/Menu Bar/StatusContainerView.swift
  11. 16
      Clocker/Menu Bar/StatusItemHandler.swift
  12. 2
      Clocker/Onboarding/FinalOnboardingViewController.swift
  13. 1
      Clocker/Onboarding/OnboardingParentViewController.swift
  14. 6
      Clocker/Onboarding/OnboardingSearchController.swift
  15. 8
      Clocker/Overall App/Logger.swift
  16. 8
      Clocker/Overall App/VersionUpdateHandler.swift
  17. 2
      Clocker/Panel/Data Layer/TimezoneData.swift
  18. 2
      Clocker/Panel/Data Layer/TimezoneDataOperations.swift
  19. 4
      Clocker/Panel/PanelController.swift
  20. 2
      Clocker/Panel/ParentPanelController.swift
  21. 2
      Clocker/Panel/UI/PanelTableView.swift
  22. 2
      Clocker/Preferences/Calendar/CalendarViewController.swift
  23. 10
      Clocker/Preferences/General/PreferencesViewController.swift

2
Clocker/Clocker/LocationController.swift

@ -111,6 +111,6 @@ extension LocationController: CLLocationManagerDelegate {
} }
func locationManager(_: CLLocationManager, didFailWithError error: Error) { 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 addUIInterruptionMonitor(withDescription: "Reminders Access") { (alert) -> Bool in
print("Interruption Handler called") Logger.info("Interruption Handler called")
print(alert) Logger.info(alert)
let alertButton = alert.buttons["OK"] let alertButton = alert.buttons["OK"]
if alertButton.exists { if alertButton.exists {
print("Okay button found") Logger.info("Okay button found")
alertButton.tap() alertButton.tap()
return true return true
} }

2
Clocker/ClockerUITests/PreferencesTest.swift

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

2
Clocker/Dependencies/Date Additions/TimeChunk.swift

@ -67,7 +67,7 @@ public struct TimeChunk {
*/ */
public func to(_ unit: TimeUnits) -> Int { public func to(_ unit: TimeUnits) -> Int {
if months != 0 { 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 return 0
} }
if unit == .seconds { if unit == .seconds {

8
Clocker/Dependencies/Date Additions/TimePeriod.swift

@ -390,7 +390,7 @@ public extension TimePeriodProtocol {
end = end?.add(chunk) end = end?.add(chunk)
case .center: case .center:
// Do not lengthen by TimeChunk at 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: case .end:
beginning = beginning?.subtract(chunk) beginning = beginning?.subtract(chunk)
} }
@ -426,7 +426,7 @@ public extension TimePeriodProtocol {
end = end?.subtract(chunk) end = end?.subtract(chunk)
case .center: case .center:
// Do not shorten by TimeChunk at 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: case .end:
beginning = beginning?.add(chunk) beginning = beginning?.add(chunk)
} }
@ -561,7 +561,7 @@ open class TimePeriod: TimePeriodProtocol {
timePeriod.beginning = beginning timePeriod.beginning = beginning
timePeriod.end = end?.add(chunk) timePeriod.end = end?.add(chunk)
case .center: 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: case .end:
timePeriod.beginning = beginning?.add(-chunk) timePeriod.beginning = beginning?.add(-chunk)
timePeriod.end = end timePeriod.end = end
@ -610,7 +610,7 @@ open class TimePeriod: TimePeriodProtocol {
timePeriod.beginning = beginning timePeriod.beginning = beginning
timePeriod.end = end?.subtract(chunk) timePeriod.end = end?.subtract(chunk)
case .center: 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: case .end:
timePeriod.beginning = beginning?.add(-chunk) timePeriod.beginning = beginning?.add(-chunk)
timePeriod.end = end timePeriod.end = end

2
Clocker/Dependencies/Date Additions/TimePeriodChain.swift

@ -79,7 +79,7 @@ open class TimePeriodChain: TimePeriodGroup {
// Insert new period // Insert new period
periods.insert(period, at: index) periods.insert(period, at: index)
} else { } 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 return
} }

14
Clocker/Events and Reminders/CalendarHandler.swift

@ -66,7 +66,7 @@ extension EventCenter {
let timeForEventToStart = event.event.startDate.timeIntervalSinceNow / 60 let timeForEventToStart = event.event.startDate.timeIntervalSinceNow / 60
if timeForEventToStart > 30 { 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 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 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() { func saveDefaultIdentifiersList() {
@ -224,7 +224,7 @@ extension EventCenter {
if !allCalendars.isEmpty { if !allCalendars.isEmpty {
UserDefaults.standard.set(allCalendars, forKey: CLSelectedCalendars) 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() self.filterEvents()
} }
} }
@ -259,7 +259,7 @@ extension EventCenter {
func fetchEvents(_ start: Int, _ end: Int) { func fetchEvents(_ start: Int, _ end: Int) {
if calendarAccessDenied() || calendarAccessNotDetermined() { if calendarAccessDenied() || calendarAccessNotDetermined() {
print("Refetching aborted because we don't have permission!") Logger.info("Refetching aborted because we don't have permission!")
return return
} }
@ -294,7 +294,7 @@ extension EventCenter {
while date.compare(final) == .orderedAscending { while date.compare(final) == .orderedAscending {
guard var nextDate = autoupdatingCalendar.date(byAdding: Calendar.Component.day, value: 1, to: date) else { 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 return
} }
nextDate = autoupdatingCalendar.startOfDay(for: nextDate) nextDate = autoupdatingCalendar.startOfDay(for: nextDate)
@ -320,7 +320,7 @@ extension EventCenter {
eventsForDate = eventsForDateMapper eventsForDate = eventsForDateMapper
print("Fetched events for \(eventsForDate.count) days") Logger.info("Fetched events for \(eventsForDate.count) days")
filterEvents() filterEvents()
} }

2
Clocker/Events and Reminders/EventCenter.swift

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

2
Clocker/Menu Bar/MenubarHandler.swift

@ -45,7 +45,7 @@ class MenubarHandler: NSObject {
let timeForEventToStart = event.event.startDate.timeIntervalSinceNow / 60 let timeForEventToStart = event.event.startDate.timeIntervalSinceNow / 60
if timeForEventToStart > 30 { 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 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 { 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) 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() 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 menubarTimer?.tolerance = shouldDisplaySeconds ? 0.5 : 20
guard let runLoopTimer = menubarTimer else { guard let runLoopTimer = menubarTimer else {
print("Timer is unexpectedly nil") Logger.info("Timer is unexpectedly nil")
return return
} }
@ -230,12 +230,12 @@ class StatusItemHandler: NSObject {
} else if let minutes = components.minute { } else if let minutes = components.minute {
components.minute = minutes + 1 components.minute = minutes + 1
} else { } else {
print("Unable to create date components for the menubar timewr") Logger.info("Unable to create date components for the menubar timewr")
return nil return nil
} }
guard let fireDate = nsCalendar.date(from: components) else { guard let fireDate = nsCalendar.date(from: components) else {
print("Unable to form Fire Date") Logger.info("Unable to form Fire Date")
return nil return nil
} }
@ -263,7 +263,7 @@ class StatusItemHandler: NSObject {
} }
private func setupForStandardTextMode() { private func setupForStandardTextMode() {
print("Initializing menubar timer") Logger.info("Initializing menubar timer")
// Let's invalidate the previous timer // Let's invalidate the previous timer
menubarTimer?.invalidate() menubarTimer?.invalidate()
@ -281,7 +281,7 @@ class StatusItemHandler: NSObject {
let menubarFavourites = DataStore.shared().menubarTimezones() ?? [] let menubarFavourites = DataStore.shared().menubarTimezones() ?? []
if menubarFavourites.isEmpty, DataStore.shared().shouldDisplay(.showMeetingInMenubar) == false { if menubarFavourites.isEmpty, DataStore.shared().shouldDisplay(.showMeetingInMenubar) == false {
print("Invalidating menubar timer!") Logger.info("Invalidating menubar timer!")
invalidation() invalidation()
@ -290,7 +290,7 @@ class StatusItemHandler: NSObject {
} }
} else if sync { } else if sync {
print("Invalidating menubar timer for sync purposes!") Logger.info("Invalidating menubar timer for sync purposes!")
invalidation() invalidation()
@ -299,7 +299,7 @@ class StatusItemHandler: NSObject {
} }
} else { } 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]? { private func extraData() -> [String: String]? {
guard let validEmail = emailValidator.validate(field: emailTextField) else { 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 return nil
} }

1
Clocker/Onboarding/OnboardingParentViewController.swift

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

6
Clocker/Onboarding/OnboardingSearchController.swift

@ -136,7 +136,7 @@ class OnboardingSearchController: NSViewController {
let decodedObject = try jsonDecoder.decode(Timezone.self, from: data) let decodedObject = try jsonDecoder.decode(Timezone.self, from: data)
return decodedObject return decodedObject
} catch { } catch {
print("decodedObject error: \n\(error)") Logger.info("decodedObject error: \n\(error)")
return nil return nil
} }
} }
@ -364,7 +364,7 @@ class OnboardingSearchController: NSViewController {
let decodedObject = try jsonDecoder.decode(SearchResult.self, from: data) let decodedObject = try jsonDecoder.decode(SearchResult.self, from: data)
return decodedObject return decodedObject
} catch { } catch {
print("decodedObject error: \n\(error)") Logger.info("decodedObject error: \n\(error)")
return nil return nil
} }
} }
@ -453,7 +453,7 @@ extension OnboardingSearchController: NSSearchFieldDelegate {
return false return false
} }
print("Not Handled") Logger.info("Not Handled")
// return true if the action was handled; otherwise false // return true if the action was handled; otherwise false
return false return false
} }

8
Clocker/Overall App/Logger.swift

@ -7,7 +7,13 @@ import os.signpost
class Logger: NSObject { class Logger: NSObject {
class func log(object annotations: [String: Any]?, for event: NSString) { class func log(object annotations: [String: Any]?, for event: NSString) {
if #available(OSX 10.14, *) { 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 { 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: "")! return URL(string: "")!
} }
@ -197,7 +197,7 @@ class VersionUpdateHandler: NSObject {
if checkAtLaunch { if checkAtLaunch {
checkIfNewVersion() checkIfNewVersion()
} else if verboseLogging { } 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 remoteVersionsDict.count <= 0 {
if downloadError != nil { if downloadError != nil {
print("Update Check Failed because of \(downloadError!.localizedDescription)") Logger.info("Update Check Failed because of \(downloadError!.localizedDescription)")
} else { } else {
print("Version Update Check because an unknown error occurred") Logger.info("Version Update Check because an unknown error occurred")
} }
} }
return return

2
Clocker/Panel/Data Layer/TimezoneData.swift

@ -231,7 +231,7 @@ class TimezoneData: NSObject, NSCoding {
let old = NSKeyedUnarchiver.unarchiveObject(with: timezone) let old = NSKeyedUnarchiver.unarchiveObject(with: timezone)
if let oldModel = old as? CLTimezoneData { if let oldModel = old as? CLTimezoneData {
// Convert it to new model and add it // 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) let newTimezone = TimezoneData(with: oldModel)
newModels.append(newTimezone) newModels.append(newTimezone)
} else if let newModel = old as? TimezoneData { } 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 let timeForEventToStart = event.event.startDate.timeIntervalSinceNow / 60
if timeForEventToStart > 30 { 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 continue
} }

4
Clocker/Panel/PanelController.swift

@ -239,7 +239,7 @@ class PanelController: ParentPanelController {
} }
private func startTimer() { private func startTimer() {
print("Start timer called") Logger.info("Start timer called")
parentTimer = Repeater(interval: .seconds(1), mode: .infinite) { _ in parentTimer = Repeater(interval: .seconds(1), mode: .infinite) { _ in
OperationQueue.main.addOperation { OperationQueue.main.addOperation {
@ -254,7 +254,7 @@ class PanelController: ParentPanelController {
if count >= 1 || DataStore.shared().shouldDisplay(.showMeetingInMenubar) { if count >= 1 || DataStore.shared().shouldDisplay(.showMeetingInMenubar) {
if let delegate = NSApplication.shared.delegate as? AppDelegate { 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) delegate.invalidateMenubarTimer(false)
} }

2
Clocker/Panel/ParentPanelController.swift

@ -1042,6 +1042,6 @@ extension ParentPanelController: NSCollectionViewDataSource, NSCollectionViewDel
} }
func collectionView(_: NSCollectionView, didSelectItemsAt indexPaths: Set<IndexPath>) { 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) { private func evaluateForHighlight(at point: NSPoint) {
if enableHover == false { 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 return
} }

2
Clocker/Preferences/Calendar/CalendarViewController.swift

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

10
Clocker/Preferences/General/PreferencesViewController.swift

@ -420,7 +420,7 @@ extension PreferencesViewController {
self.placeholderLabel.placeholderString = "Searching for \(searchString)" self.placeholderLabel.placeholderString = "Searching for \(searchString)"
print(self.placeholderLabel.placeholderString ?? "") Logger.info(self.placeholderLabel.placeholderString ?? "")
self.dataTask = NetworkManager.task(with: self.generateSearchURL(), self.dataTask = NetworkManager.task(with: self.generateSearchURL(),
completionHandler: { [weak self] response, error in completionHandler: { [weak self] response, error in
@ -474,7 +474,7 @@ extension PreferencesViewController {
return false return false
} }
print(searchResultsDataSource.timezoneFilteredArray) Logger.info(searchResultsDataSource.timezoneFilteredArray.debugDescription)
} }
private func generateSearchURL() -> String { private func generateSearchURL() -> String {
@ -528,7 +528,7 @@ extension PreferencesViewController {
private func reloadSearchResults() { private func reloadSearchResults() {
if searchResultsDataSource.calculateChangesets() { if searchResultsDataSource.calculateChangesets() {
print("Reloading Search Results") Logger.info("Reloading Search Results")
availableTimezoneTableView.reloadData() availableTimezoneTableView.reloadData()
} }
} }
@ -540,7 +540,7 @@ extension PreferencesViewController {
let decodedObject = try jsonDecoder.decode(SearchResult.self, from: data) let decodedObject = try jsonDecoder.decode(SearchResult.self, from: data)
return decodedObject return decodedObject
} catch { } catch {
print("decodedObject error: \n\(error)") Logger.info("decodedObject error: \n\(error)")
return nil return nil
} }
} }
@ -552,7 +552,7 @@ extension PreferencesViewController {
let decodedObject = try jsonDecoder.decode(Timezone.self, from: data) let decodedObject = try jsonDecoder.decode(Timezone.self, from: data)
return decodedObject return decodedObject
} catch { } catch {
print("decodedObject error: \n\(error)") Logger.info("decodedObject error: \n\(error)")
return nil return nil
} }
} }

Loading…
Cancel
Save