Skip to content

Commit f97c194

Browse files
committed
Log critical failures
1 parent 1d0d40b commit f97c194

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

openmapview/src/main/kotlin/de/afarber/openmapview/DiskTileCache.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package de.afarber.openmapview
1010
import android.content.Context
1111
import android.graphics.Bitmap
1212
import android.graphics.BitmapFactory
13+
import android.util.Log
1314
import com.jakewharton.disklrucache.DiskLruCache
1415
import java.io.File
1516
import java.io.IOException
@@ -28,6 +29,7 @@ class DiskTileCache(
2829
private val diskCache: DiskLruCache?
2930

3031
companion object {
32+
private val TAG = DiskTileCache::class.java.simpleName
3133
private const val DISK_CACHE_VERSION = 1
3234
private const val VALUE_COUNT = 1
3335
}
@@ -38,6 +40,7 @@ class DiskTileCache(
3840
try {
3941
DiskLruCache.open(cacheDir, DISK_CACHE_VERSION, VALUE_COUNT, maxSize)
4042
} catch (e: IOException) {
43+
Log.e(TAG, "Failed to initialize disk cache at $cacheDir", e)
4144
null
4245
}
4346
}
@@ -50,6 +53,7 @@ class DiskTileCache(
5053
BitmapFactory.decodeStream(inputStream)
5154
}
5255
} catch (e: IOException) {
56+
Log.w(TAG, "Failed to read tile $key from disk cache", e)
5357
null
5458
}
5559
}
@@ -66,27 +70,28 @@ class DiskTileCache(
6670
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream)
6771
editor.commit()
6872
} catch (e: IOException) {
73+
Log.w(TAG, "Failed to write tile $key to disk cache", e)
6974
editor.abort()
7075
}
7176
}
7277
} catch (e: IOException) {
73-
// Ignore disk cache errors
78+
Log.w(TAG, "Failed to edit tile $key in disk cache", e)
7479
}
7580
}
7681

7782
fun clear() {
7883
try {
7984
diskCache?.delete()
8085
} catch (e: IOException) {
81-
// Ignore
86+
Log.w(TAG, "Failed to clear disk cache", e)
8287
}
8388
}
8489

8590
fun close() {
8691
try {
8792
diskCache?.close()
8893
} catch (e: IOException) {
89-
// Ignore
94+
Log.w(TAG, "Failed to close disk cache", e)
9095
}
9196
}
9297

openmapview/src/main/kotlin/de/afarber/openmapview/TileCache.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package de.afarber.openmapview
99

1010
import android.content.Context
1111
import android.graphics.Bitmap
12+
import android.util.Log
1213
import android.util.LruCache
1314
import kotlinx.coroutines.CoroutineScope
1415
import kotlinx.coroutines.Dispatchers
@@ -24,6 +25,10 @@ import kotlinx.coroutines.launch
2425
class TileCache(
2526
context: Context? = null,
2627
) {
28+
companion object {
29+
private val TAG = TileCache::class.java.simpleName
30+
}
31+
2732
// Use 1/8 of available heap memory for tile cache
2833
private val maxMemory = (Runtime.getRuntime().maxMemory() / 1024).toInt()
2934
private val cacheSize = maxMemory / 8
@@ -50,7 +55,7 @@ class TileCache(
5055
try {
5156
diskCache?.put(key, oldValue)
5257
} catch (e: Exception) {
53-
// Ignore errors when disk cache is closed
58+
Log.w(TAG, "Failed to write evicted tile to disk cache", e)
5459
}
5560
}
5661
}
@@ -87,7 +92,7 @@ class TileCache(
8792
try {
8893
diskCache?.clear()
8994
} catch (e: Exception) {
90-
// Ignore errors during clear
95+
Log.w(TAG, "Failed to clear disk cache", e)
9196
}
9297
}
9398

@@ -96,7 +101,7 @@ class TileCache(
96101
diskCache?.close()
97102
diskCache = null
98103
} catch (e: Exception) {
99-
// Ignore errors during close
104+
Log.w(TAG, "Failed to close disk cache", e)
100105
}
101106
}
102107
}

openmapview/src/main/kotlin/de/afarber/openmapview/TileDownloader.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ package de.afarber.openmapview
99

1010
import android.graphics.Bitmap
1111
import android.graphics.BitmapFactory
12+
import android.util.Log
1213
import io.ktor.client.HttpClient
1314
import io.ktor.client.engine.android.Android
1415
import io.ktor.client.request.get
1516
import io.ktor.client.request.header
1617
import io.ktor.client.statement.readBytes
1718

1819
class TileDownloader {
20+
companion object {
21+
private val TAG = TileDownloader::class.java.simpleName
22+
}
23+
1924
private val client =
2025
HttpClient(Android) {
2126
engine {
@@ -41,6 +46,7 @@ class TileDownloader {
4146
}
4247
BitmapFactory.decodeByteArray(bytes, 0, bytes.size, options)
4348
} catch (e: Exception) {
49+
Log.w(TAG, "Failed to download tile from $url", e)
4450
null
4551
}
4652

0 commit comments

Comments
 (0)