From 3d85969caf4df05e0f2579fbe96af279179b6083 Mon Sep 17 00:00:00 2001 From: Jacob Fielding Date: Sat, 7 Dec 2024 18:28:35 -0800 Subject: [PATCH] Added and tested android logger (#388) --- .../com/stadiamaps/ferrostar/MainActivity.kt | 4 +++ apple/Sources/UniFFI/ferrostar.swift | 8 +++++ common/Cargo.lock | 29 +++++++++++++++++++ common/ferrostar/Cargo.toml | 4 +++ common/ferrostar/src/lib.rs | 24 +++++++++++++++ 5 files changed, 69 insertions(+) diff --git a/android/demo-app/src/main/java/com/stadiamaps/ferrostar/MainActivity.kt b/android/demo-app/src/main/java/com/stadiamaps/ferrostar/MainActivity.kt index 47c26cf3..d25ef67f 100644 --- a/android/demo-app/src/main/java/com/stadiamaps/ferrostar/MainActivity.kt +++ b/android/demo-app/src/main/java/com/stadiamaps/ferrostar/MainActivity.kt @@ -10,6 +10,7 @@ import androidx.compose.material3.Surface import com.stadiamaps.ferrostar.core.AndroidTtsStatusListener import com.stadiamaps.ferrostar.ui.theme.FerrostarTheme import java.util.Locale +import uniffi.ferrostar.createFerrostarLogger class MainActivity : ComponentActivity(), AndroidTtsStatusListener { companion object { @@ -44,6 +45,9 @@ class MainActivity : ComponentActivity(), AndroidTtsStatusListener { // AppModule.locationProvider.lastLocation = initialSimulatedLocation // AppModule.locationProvider.warpFactor = 2u + // Setup the global Ferrostar logger + createFerrostarLogger() + // Edge to edge (this will be default in Android 15) // See https://developer.android.com/codelabs/edge-to-edge#0 // How to: https://developer.android.com/develop/ui/compose/layouts/insets#insets-setup diff --git a/apple/Sources/UniFFI/ferrostar.swift b/apple/Sources/UniFFI/ferrostar.swift index 5d857b84..edee864e 100644 --- a/apple/Sources/UniFFI/ferrostar.swift +++ b/apple/Sources/UniFFI/ferrostar.swift @@ -6165,6 +6165,11 @@ public func advanceLocationSimulation(state: LocationSimulationState) -> Locatio ) }) } +public func createFerrostarLogger() {try! rustCall() { + uniffi_ferrostar_fn_func_create_ferrostar_logger($0 + ) +} +} /** * Creates a [`RouteResponseParser`] capable of parsing OSRM responses. * @@ -6285,6 +6290,9 @@ private var initializationResult: InitializationResult = { if (uniffi_ferrostar_checksum_func_advance_location_simulation() != 26307) { return InitializationResult.apiChecksumMismatch } + if (uniffi_ferrostar_checksum_func_create_ferrostar_logger() != 18551) { + return InitializationResult.apiChecksumMismatch + } if (uniffi_ferrostar_checksum_func_create_osrm_response_parser() != 16550) { return InitializationResult.apiChecksumMismatch } diff --git a/common/Cargo.lock b/common/Cargo.lock index 8592df35..7bf34e2c 100644 --- a/common/Cargo.lock +++ b/common/Cargo.lock @@ -35,6 +35,23 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" +[[package]] +name = "android_log-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ecc8056bf6ab9892dcd53216c83d1597487d7dacac16c8df6b877d127df9937" + +[[package]] +name = "android_logger" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b07e8e73d720a1f2e4b6014766e6039fd2e96a4fa44e2a78d0e1fa2ff49826" +dependencies = [ + "android_log-sys", + "env_filter", + "log", +] + [[package]] name = "android_system_properties" version = "0.1.5" @@ -428,6 +445,16 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" +[[package]] +name = "env_filter" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" +dependencies = [ + "log", + "regex", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -438,12 +465,14 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" name = "ferrostar" version = "0.23.0" dependencies = [ + "android_logger", "assert-json-diff", "chrono", "geo", "getrandom", "insta", "itertools 0.13.0", + "log", "polyline", "proptest", "rand", diff --git a/common/ferrostar/Cargo.toml b/common/ferrostar/Cargo.toml index 72bb0692..2188954d 100644 --- a/common/ferrostar/Cargo.toml +++ b/common/ferrostar/Cargo.toml @@ -43,6 +43,10 @@ wasm-bindgen = { version = "0.2.93", optional = true } web-time = { version = "1.1.0", features = ["serde"], optional = true } itertools = "0.13.0" tsify = { version = "0.4.5", default-features = false, features = ["js"] } +log = "0.4.22" + +[target.'cfg(target_os = "android")'.dependencies] +android_logger = { version = "0.14.1" } [build-dependencies] uniffi = { workspace = true, features = ["build"] } diff --git a/common/ferrostar/src/lib.rs b/common/ferrostar/src/lib.rs index 9bb72d88..682a5edf 100644 --- a/common/ferrostar/src/lib.rs +++ b/common/ferrostar/src/lib.rs @@ -23,6 +23,9 @@ #[cfg(feature = "alloc")] extern crate alloc; +#[cfg(target_os = "android")] +use android_logger::{Config, FilterBuilder}; + pub mod algorithms; pub mod deviation_detection; pub mod models; @@ -30,6 +33,27 @@ pub mod navigation_controller; pub mod routing_adapters; pub mod simulation; +#[cfg(target_os = "android")] +fn init_logger() { + android_logger::init_once( + Config::default() + .with_max_level(log::LevelFilter::Trace) + .with_tag("ferrostar.core"), + ); + log::info!("Ferrostar android logger initialized"); +} + +#[cfg(not(target_os = "android"))] +fn init_logger() { + // Add fallback logging initialization for non-Android platforms +} + +#[cfg(feature = "uniffi")] +#[uniffi::export] +pub fn create_ferrostar_logger() { + init_logger(); +} + #[cfg(feature = "uniffi")] mod uniffi_deps { pub use crate::models::Route;