Skip to content

Commit

Permalink
V10.5 port: Refactor Mapbox logging (#1290)
Browse files Browse the repository at this point in the history
* Refactor Mapbox logging

* Fix tests

* Format fixes

* Fix tests, remove shadow logger

* Update changelog and api files

* Remove redundant

* Add unmockks
  • Loading branch information
kiryldz committed Apr 20, 2022
1 parent e612d05 commit cd19651
Show file tree
Hide file tree
Showing 96 changed files with 567 additions and 666 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Mapbox welcomes participation and contributions from everyone.

# main
## Features ✨ and improvements 🏁
* Refactor all Mapbox logs so that Logcat tag will always be 'Mapbox' allowing easier filtering. Previous log tag will become part of the log message now. ([#1276](https://github.com/mapbox/mapbox-maps-android/pull/1276))

## Bug fixes 🐞
* Fix NaN latitude native crash rarely happening during `MapboxMap#flyTo`. ([#1271](https://github.com/mapbox/mapbox-maps-android/pull/1271))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.graphics.BitmapFactory
import androidx.annotation.UiThread
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import com.mapbox.common.Logger
import com.mapbox.geojson.Point
import com.mapbox.maps.*
import com.mapbox.maps.dsl.cameraOptions
Expand Down Expand Up @@ -503,7 +502,7 @@ class ObservableExtensionTest : BaseMapTest() {
activity.runOnUiThread {
mapboxMap.subscribe(
{
Logger.e(TAG, it.toString())
logE(TAG, it.toString())
},
SUPPORTED_EVENTS
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import com.mapbox.common.Logger
import com.mapbox.maps.*
import com.mapbox.maps.extension.observable.eventdata.MapLoadingErrorEventData
import com.mapbox.maps.extension.observable.getResourceEventData
Expand All @@ -30,14 +29,14 @@ class DebugModeActivity : AppCompatActivity() {
)
private val extensionObservable = Observer { event ->
val data = event.getResourceEventData()
Logger.i(
logI(
TAG,
"extensionObservable DataSource: ${data.dataSource}\nRequest: ${data.request}\nResponse: ${data.response}\nCancelled: ${data.cancelled}"
)
}

private val observable = Observer { event ->
Logger.i(
logI(
TAG,
"Type: ${event.type}\nValue: ${event.data.contents}"
)
Expand All @@ -62,54 +61,54 @@ class DebugModeActivity : AppCompatActivity() {

private fun registerListeners(mapboxMap: MapboxMap) {
mapboxMap.addOnStyleLoadedListener {
Logger.i(TAG, "OnStyleLoadedListener: $it")
logI(TAG, "OnStyleLoadedListener: $it")
}
mapboxMap.addOnStyleDataLoadedListener {
Logger.i(TAG, "OnStyleDataLoadedListener: $it")
logI(TAG, "OnStyleDataLoadedListener: $it")
}
mapboxMap.addOnStyleImageMissingListener {
Logger.i(TAG, "OnStyleImageMissingListener: $it")
logI(TAG, "OnStyleImageMissingListener: $it")
}
mapboxMap.addOnStyleImageUnusedListener {
Logger.i(TAG, "OnStyleImageUnusedListener: $it")
logI(TAG, "OnStyleImageUnusedListener: $it")
}
mapboxMap.addOnMapIdleListener {
Logger.i(TAG, "OnMapIdleListener: $it")
logI(TAG, "OnMapIdleListener: $it")
}
mapboxMap.addOnMapLoadErrorListener(object : OnMapLoadErrorListener {
override fun onMapLoadError(eventData: MapLoadingErrorEventData) {
Logger.i(TAG, "OnMapLoadErrorListener: $eventData")
logI(TAG, "OnMapLoadErrorListener: $eventData")
}
})
mapboxMap.addOnMapLoadedListener {
Logger.i(TAG, "OnMapLoadedListener: $it")
logI(TAG, "OnMapLoadedListener: $it")
}
mapboxMap.addOnCameraChangeListener {
Logger.i(TAG, "OnCameraChangeListener: $it")
logI(TAG, "OnCameraChangeListener: $it")
}
mapboxMap.addOnRenderFrameStartedListener {
Logger.i(TAG, "OnRenderFrameStartedListener: $it")
logI(TAG, "OnRenderFrameStartedListener: $it")
}
mapboxMap.addOnRenderFrameFinishedListener {
Logger.i(
logI(
TAG,
"OnRenderFrameFinishedListener: $it"
)
}
mapboxMap.addOnSourceAddedListener {
Logger.i(
logI(
TAG,
"OnSourceAddedListener: $it"
)
}
mapboxMap.addOnSourceDataLoadedListener {
Logger.i(
logI(
TAG,
"OnSourceDataLoadedListener: $it"
)
}
mapboxMap.addOnSourceRemovedListener {
Logger.i(
logI(
TAG,
"OnSourceRemovedListener: $it"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.mapbox.maps.testapp.examples
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.mapbox.common.Logger
import com.mapbox.geojson.Point
import com.mapbox.maps.*
import com.mapbox.maps.testapp.databinding.ActivityLegacyOfflineBinding
Expand All @@ -21,11 +20,11 @@ class LegacyOfflineActivity : AppCompatActivity() {

private val regionObserver: OfflineRegionObserver = object : OfflineRegionObserver {
override fun mapboxTileCountLimitExceeded(limit: Long) {
Logger.e(TAG, "Mapbox tile count max (= $limit) has exceeded!")
logE(TAG, "Mapbox tile count max (= $limit) has exceeded!")
}

override fun statusChanged(status: OfflineRegionStatus) {
Logger.d(
logD(
TAG,
"${status.completedResourceCount}/${status.requiredResourceCount} resources; ${status.completedResourceSize} bytes downloaded."
)
Expand All @@ -36,7 +35,7 @@ class LegacyOfflineActivity : AppCompatActivity() {
}

override fun responseError(error: ResponseError) {
Logger.e(TAG, "onError: ${error.reason}, ${error.message}")
logE(TAG, "onError: ${error.reason}, ${error.message}")
offlineRegion.setOfflineRegionDownloadState(OfflineRegionDownloadState.INACTIVE)
}
}
Expand All @@ -49,7 +48,7 @@ class LegacyOfflineActivity : AppCompatActivity() {
it.setOfflineRegionDownloadState(OfflineRegionDownloadState.ACTIVE)
}
} else {
Logger.e(TAG, expected.error!!)
logE(TAG, expected.error!!)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.toBitmap
import com.mapbox.bindgen.Value
import com.mapbox.common.Logger
import com.mapbox.geojson.FeatureCollection
import com.mapbox.maps.*
import com.mapbox.maps.extension.style.expressions.dsl.generated.*
Expand Down Expand Up @@ -58,7 +57,7 @@ class RuntimeStylingActivity : AppCompatActivity() {
addLayerWithoutStyleExtension(style)

val source = style.getSource("composite") as VectorSource
Logger.e(TAG, "getSource: $source")
logE(TAG, "getSource: $source")
}

private fun addImage(style: Style) {
Expand All @@ -69,10 +68,10 @@ class RuntimeStylingActivity : AppCompatActivity() {
true
)
expected.error?.let {
Logger.e(TAG, it)
logE(TAG, it)
}
expected.value?.let {
Logger.d(TAG, it.toString())
logD(TAG, it.toString())
}
}

Expand Down Expand Up @@ -157,9 +156,9 @@ class RuntimeStylingActivity : AppCompatActivity() {
cluster(true)
prefetchZoomDelta(1)
}
Logger.i(TAG, source.toString())
logI(TAG, source.toString())
style.addSource(source)
Logger.i(TAG, "prefetchZoomDelta : ${source.prefetchZoomDelta}")
logI(TAG, "prefetchZoomDelta : ${source.prefetchZoomDelta}")
}

private fun addSymbolLayer(style: Style) {
Expand Down Expand Up @@ -217,7 +216,7 @@ class RuntimeStylingActivity : AppCompatActivity() {
iconIgnorePlacement(false)
}
style.addLayer(symbolLayer)
Logger.i(TAG, symbolLayer.iconOpacityAsExpression.toString())
logI(TAG, symbolLayer.iconOpacityAsExpression.toString())
}

private fun addFillSource(style: Style) {
Expand Down Expand Up @@ -261,7 +260,7 @@ class RuntimeStylingActivity : AppCompatActivity() {
)
)
}
Logger.i(TAG, polygon.toString())
logI(TAG, polygon.toString())
style.addSource(polygon)
}

Expand All @@ -288,7 +287,7 @@ class RuntimeStylingActivity : AppCompatActivity() {
}
)
fillLayer.visibility(Visibility.VISIBLE)
Logger.i(TAG, fillLayer.fillColorAsExpression.toString())
logI(TAG, fillLayer.fillColorAsExpression.toString())
}

private fun addFillExtrusionLayer(style: Style) {
Expand Down Expand Up @@ -347,10 +346,10 @@ class RuntimeStylingActivity : AppCompatActivity() {
null
)
expected.error?.let {
Logger.e(TAG, it)
logE(TAG, it)
}
expected.value?.let {
Logger.d(TAG, it.toString())
logD(TAG, it.toString())
}

val sourceParams = HashMap<String, Value>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ import android.os.Handler
import android.os.Looper
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.mapbox.common.Logger
import com.mapbox.geojson.Feature
import com.mapbox.geojson.FeatureCollection
import com.mapbox.geojson.Point
import com.mapbox.maps.CameraOptions
import com.mapbox.maps.MapView
import com.mapbox.maps.MapboxMap
import com.mapbox.maps.Style
import com.mapbox.maps.*
import com.mapbox.maps.extension.style.layers.addLayer
import com.mapbox.maps.extension.style.layers.generated.symbolLayer
import com.mapbox.maps.extension.style.sources.addSource
Expand Down Expand Up @@ -89,7 +85,7 @@ class SpaceStationLocationActivity : AppCompatActivity() {
if (latitude != null && longitude != null) {
updateMarkerPosition(longitude = longitude, latitude = latitude)
} else {
Logger.w(TAG, "Wrong response position")
logW(TAG, "Wrong response position")
}
}

Expand All @@ -100,9 +96,9 @@ class SpaceStationLocationActivity : AppCompatActivity() {
// If retrofit fails or the API was unreachable, an error will be called.
// to check if throwable is null, then give a custom message.
if (throwable.message == null) {
Logger.e(TAG, "Http connection failed")
logE(TAG, "Http connection failed")
} else {
Logger.e(TAG, "onFailure: ${throwable.message}")
logE(TAG, "onFailure: ${throwable.message}")
}
}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.mapbox.maps.testapp.examples.annotation

import android.content.Context
import com.mapbox.common.Logger
import com.mapbox.geojson.Point
import com.mapbox.maps.Style
import com.mapbox.maps.logE
import okhttp3.Cache
import okhttp3.OkHttpClient
import okhttp3.Request
Expand Down Expand Up @@ -92,7 +92,7 @@ object AnnotationUtils {
}
sb.toString()
} catch (e: IOException) {
Logger.e(TAG, "Unable to parse $fileName")
logE(TAG, "Unable to parse $fileName")
null
}
}
Expand Down Expand Up @@ -120,7 +120,7 @@ object AnnotationUtils {
}
sb.toString()
} catch (e: IOException) {
Logger.e(TAG, "Unable to download $url")
logE(TAG, "Unable to download $url")
null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import com.mapbox.common.Logger
import com.mapbox.geojson.Point
import com.mapbox.maps.CameraOptions
import com.mapbox.maps.LayerPosition
import com.mapbox.maps.MapboxMap
import com.mapbox.maps.Style
import com.mapbox.maps.*
import com.mapbox.maps.testapp.R
import com.mapbox.maps.testapp.databinding.ActivityCustomLayerBinding

Expand Down Expand Up @@ -53,7 +49,7 @@ class CustomLayerActivity : AppCompatActivity() {
LayerPosition(null, "building", null)
)
expected.error?.let {
Logger.e(TAG, "Add custom layer exception $it")
logE(TAG, "Add custom layer exception $it")
}
binding.fab.setImageResource(R.drawable.ic_layers_clear)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.mapbox.maps.testapp.examples.customlayer

import android.opengl.GLES20
import com.mapbox.common.Logger
import com.mapbox.maps.CustomLayerHost
import com.mapbox.maps.CustomLayerRenderParameters
import com.mapbox.maps.logD
import com.mapbox.maps.logW
import com.mapbox.maps.testapp.BuildConfig
import java.nio.ByteBuffer
import java.nio.ByteOrder
Expand Down Expand Up @@ -36,7 +37,7 @@ class ExampleCustomLayer : CustomLayerHost {
override fun initialize() {
val maxAttrib = IntArray(1)
GLES20.glGetIntegerv(GLES20.GL_MAX_VERTEX_ATTRIBS, maxAttrib, 0)
Logger.d(TAG, "Max vertex attributes: ${maxAttrib[0]}")
logD(TAG, "Max vertex attributes: ${maxAttrib[0]}")

// load and compile shaders
vertexShader = loadShader(
Expand Down Expand Up @@ -101,7 +102,7 @@ class ExampleCustomLayer : CustomLayerHost {
}

override fun contextLost() {
Logger.w(TAG, "contextLost")
logW(TAG, "contextLost")
program = 0
}

Expand Down Expand Up @@ -177,7 +178,7 @@ class ExampleCustomLayer : CustomLayerHost {
if (BuildConfig.DEBUG) {
when (val error = GLES20.glGetError()) {
GLES20.GL_NO_ERROR -> {
Logger.d(TAG, "$cmd -> no error")
logD(TAG, "$cmd -> no error")
}
GLES20.GL_INVALID_ENUM -> throw RuntimeException("$cmd -> error in gl: GL_INVALID_ENUM")
GLES20.GL_INVALID_VALUE -> throw RuntimeException("$cmd -> error in gl: GL_INVALID_VALUE")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import com.mapbox.common.Logger
import com.mapbox.geojson.Point
import com.mapbox.maps.CameraOptions
import com.mapbox.maps.LayerPosition
import com.mapbox.maps.MapboxMap
import com.mapbox.maps.Style
import com.mapbox.maps.*
import com.mapbox.maps.testapp.R
import com.mapbox.maps.testapp.databinding.ActivityCustomLayerBinding

Expand Down Expand Up @@ -55,7 +51,7 @@ class NativeCustomLayerActivity : AppCompatActivity() {
LayerPosition(null, "building", null)
)
expected.error?.let {
Logger.e(TAG, "Add custom layer exception $it")
logE(TAG, "Add custom layer exception $it")
}
binding.fab.setImageResource(R.drawable.ic_layers_clear)
}
Expand Down
Loading

0 comments on commit cd19651

Please sign in to comment.