Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging functionality for CarPlay #3653

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jill-cardamon
Copy link
Contributor

This PR adds logging functionality to CarPlay to make it easier for us to debug locally.

Still needs testing on a real CarPlay head unit.
Additional ideas:

  • output to local server

@jill-cardamon jill-cardamon added op-ex Refactoring, Tech Debt or any other operational excellence work. UI Work related to visual components, Android Auto, Camera, 3D, voice, etc. CarPlay Bugs, improvements and feature requests on Apple CarPlay improvement Improvement for an existing feature. labels Dec 14, 2021
@jill-cardamon jill-cardamon added this to the v2.2 milestone Dec 14, 2021
@jill-cardamon jill-cardamon self-assigned this Dec 14, 2021
@@ -77,6 +78,7 @@ public class CarPlayManager: NSObject {

private weak var navigationService: NavigationService?
private var idleTimerCancellable: IdleTimerManager.Cancellable?
private let logger: OSLog = .init(subsystem: "com.mapbox.navigation", category: "CarPlayManager")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a factory for loggers? So that we don't duplicate subsystem value everywhere.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we can go with a simpler way: creating an internal constant for the log subsystem.

Copy link
Contributor Author

@jill-cardamon jill-cardamon Dec 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use something like OSLogManager but would probably want to consider using this manager for all of the SDK.

@@ -23,7 +26,7 @@ extension NavigationMapView {
do {
try mapView.mapboxMap.style.addSource(streetsSource, id: sourceIdentifier)
} catch {
NSLog("Failed to add \(sourceIdentifier) with error: \(error.localizedDescription).")
os_log("Failed to add %s with error: %s.", log: logger, type: .error, sourceIdentifier as CVarArg, error.localizedDescription)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The %s will be redacted out in the logs. Should it be %{public}s?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes. I will try this. Thank you

@@ -23,7 +26,7 @@ extension NavigationMapView {
do {
try mapView.mapboxMap.style.addSource(streetsSource, id: sourceIdentifier)
} catch {
NSLog("Failed to add \(sourceIdentifier) with error: \(error.localizedDescription).")
os_log("Failed to add %s with error: %s.", log: logger, type: .error, sourceIdentifier as CVarArg, error.localizedDescription)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need casting to CVarArg here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cast was needed since os_log uses StaticString

@@ -1,6 +1,9 @@
import MapboxMaps
import MapboxDirections
import MapboxCoreNavigation
import os.log

private let logger: OSLog = .init(subsystem: "com.mapbox.navigation", category: "RoadNameLabeling")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use private global constants in other classes too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We needed one here since you can't create stored properties in extensions. For consistency, we should either move constants to be global or use a manager for these OSLog constants

}

@available(iOS 15.0, *)
func getLogEntries() throws -> [OSLogEntryLog] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it for debugging? If so, don't forget to remove this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for retrieving log entries if you want to see them printed to a file instead of looking at the log via the Console. This functionality is only available via iOS 15.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are several build errors because of OSLogEntryLog. For example getting: error: cannot find type 'OSLogEntryLog' in scope.

@MaximAlien MaximAlien modified the milestones: v2.2, v2.3 Jan 20, 2022
@@ -333,6 +354,7 @@ extension CarPlayManager: CPApplicationDelegate {
interfaceController.setRootTemplate(mapTemplate, animated: false)

eventsManager.sendCarPlayConnectEvent()
os_log("CarInterfaceController did connect to window.", log: logger, type: .info)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that CPApplicationDelegate delegate methods are deprecated. We'll need similar logging for CPTemplateApplicationSceneDelegate as well. I think that it'd be also beneficial to log information regarding CPInterfaceController (e.g. its address, main template etc).

@@ -2,6 +2,7 @@ import CarPlay
import MapboxCoreNavigation
import MapboxDirections
import MapboxMaps
import os.log
Copy link
Contributor

@MaximAlien MaximAlien Feb 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to add logging for CPTemplate lifecycle callbacks in CarPlayManagerDelegate:

  • carPlayManager(_:templateWillAppear:animated:)
  • carPlayManager(_:templateDidAppear:animated:)
  • carPlayManager(_:templateWillDisappear:animated:)
  • carPlayManager(_:templateDidDisappear:animated:)

@@ -2,6 +2,7 @@ import Foundation
@_spi(Restricted) import MapboxMaps
import MapboxCoreNavigation
import MapboxDirections
import os.log
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be useful to have logging information when CarPlayActivity value changes.

@@ -561,6 +582,7 @@ extension CarPlayManager {

switch result {
case let .failure(error):
os_log("Failed to calculate routes.", log: logger, type: .debug)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like an error log type.

@@ -93,6 +95,7 @@ public class CarPlayManager: NSObject {
locationProvider.stopUpdatingHeading()
if let passiveLocationProvider = locationProvider as? PassiveLocationProvider {
passiveLocationProvider.locationManager.pauseTripSession()
os_log("Trip session paused", log: logger, type: .debug)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be good to go through all methods in CarPlayManager and see what CarPlay related methods it uses. I think that we should log all callbacks we receive from it.

@MaximAlien
Copy link
Contributor

We should add logging for CarPlaySearchController/CPSearchTemplateDelegate as well.

@MaximAlien MaximAlien modified the milestones: v2.3, v2.4 Feb 23, 2022
@MaximAlien MaximAlien modified the milestones: v2.4, v2.5 Apr 13, 2022
@MaximAlien MaximAlien removed this from the v2.5 milestone May 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CarPlay Bugs, improvements and feature requests on Apple CarPlay improvement Improvement for an existing feature. op-ex Refactoring, Tech Debt or any other operational excellence work. UI Work related to visual components, Android Auto, Camera, 3D, voice, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants