NetNewsWire icon indicating copy to clipboard operation
NetNewsWire copied to clipboard

OSLog messages that are propagating error messages should be marked public

Open vincode-io opened this issue 1 year ago • 1 comments

Some uses of OSLog in NNW are catching errors and logging the error message using a parameter. These parameters should be designated as public so that users can give us diagnostic information if an issue occurs. We should audit OSLog usage and fix this issue where appropriate.

vincode-io avatar Jul 30 '22 21:07 vincode-io

@vincode-io Proposal:

  • Move to Swift usage of OSLog (see below)
  • Implement a Logging protocol to save on repetition
import Foundation
import os.log

internal protocol Logging {
	
	var logger: Logger { get }
	static var logger: Logger { get }
	
}

extension Logging  {
	
	var logger: Logger {
		Logger(subsystem: Bundle.main.bundleIdentifier!, category: String(describing: type(of: self)))
	}
	
	static var logger: Logger {
		Logger(subsystem: Bundle.main.bundleIdentifier!, category: String(describing: type(of: self)))
	}
	
}
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, UnreadCountProvider, Logging {

    /// [...lots of code...]
    
    /// Schedules a background app refresh based on `AppDefaults.refreshInterval`.
    func scheduleBackgroundFeedRefresh() {
	let request = BGAppRefreshTaskRequest(identifier: "com.ranchero.NetNewsWire.FeedRefresh")
	request.earliestBeginDate = Date(timeIntervalSinceNow: 15 * 60)

	// We send this to a dedicated serial queue because as of 11/05/19 on iOS 13.2 the call to the
	// task scheduler can hang indefinitely.
	bgTaskDispatchQueue.async {
	    do {
		try BGTaskScheduler.shared.submit(request)
	    } catch {
		// os_log(.error, log: self.log, "Could not schedule app refresh: %@", error.localizedDescription) 
		self.logger.error("Could not schedule app refresh: \(error.localizedDescription, privacy: .public)")
	    }
	}
    }

}

Sample output using Logging:

NetNewsWire[37318:1898097] [WidgetDataEncoder] Started encoding widget data.
NetNewsWire[37318:1898346] [WidgetDataEncoder] Finished encoding widget data.
NetNewsWire[37318:1898346] [WidgetDataEncoder] Removed widget data from container.
NetNewsWire[37318:1898340] [AppDelegate] Could not schedule app refresh: The operation couldn’t be completed. (BGTaskSchedulerErrorDomain error 1.)
NetNewsWire[37318:1898346] [WidgetDataEncoder] Wrote widget data to container.
NetNewsWire[37318:1898097] [AppDelegate] Waiting for sync to finish...
NetNewsWire[37318:1898097] [AppDelegate] Refresh progress complete.
NetNewsWire[37318:1898097] [AppDelegate] Application processing suspended.

stuartbreckenridge avatar Aug 03 '22 06:08 stuartbreckenridge

Oh thank goodness

stuartbreckenridge avatar Sep 24 '22 11:09 stuartbreckenridge