Skip to content

Commit

Permalink
Added and tested android logger (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
Archdoog authored Dec 8, 2024
1 parent 0310469 commit 3d85969
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions apple/Sources/UniFFI/ferrostar.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions common/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions common/ferrostar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
24 changes: 24 additions & 0 deletions common/ferrostar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,37 @@
#[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;
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;
Expand Down

0 comments on commit 3d85969

Please sign in to comment.