Vadik Sirekanyan пре 2 година
родитељ
комит
f98da8099e

+ 3 - 3
app/src/main/java/org/sirekanyan/outline/MainState.kt

@@ -1,6 +1,5 @@
 package org.sirekanyan.outline
 
-import android.util.Log
 import android.widget.Toast
 import androidx.compose.material3.DrawerState
 import androidx.compose.material3.DrawerValue
@@ -19,6 +18,7 @@ import kotlinx.coroutines.launch
 import kotlinx.coroutines.plus
 import org.sirekanyan.outline.api.OutlineApi
 import org.sirekanyan.outline.api.model.Key
+import org.sirekanyan.outline.ext.logError
 import org.sirekanyan.outline.feature.keys.KeysErrorState
 import org.sirekanyan.outline.feature.keys.KeysLoadingState
 import org.sirekanyan.outline.feature.keys.KeysState
@@ -33,9 +33,9 @@ fun rememberMainState(api: OutlineApi): MainState {
     val scope = rememberCoroutineScope {
         CoroutineExceptionHandler { _, throwable ->
             if (throwable is UnknownHostException) {
-                Log.e("OUTLINE", "Uncaught exception: ${throwable.message}")
+                logError("Uncaught exception: ${throwable.message}", throwable = null)
             } else {
-                Log.e("OUTLINE", "Uncaught exception", throwable)
+                logError("Uncaught exception", throwable)
             }
             when (throwable) {
                 is UnknownHostException, is ConnectException -> {

+ 2 - 2
app/src/main/java/org/sirekanyan/outline/api/OutlineApi.kt

@@ -1,6 +1,5 @@
 package org.sirekanyan.outline.api
 
-import android.util.Log
 import io.ktor.client.HttpClient
 import io.ktor.client.call.body
 import io.ktor.client.engine.cio.CIO
@@ -20,6 +19,7 @@ import org.sirekanyan.outline.api.model.RenameRequest
 import org.sirekanyan.outline.api.model.Server
 import org.sirekanyan.outline.api.model.ServerNameResponse
 import org.sirekanyan.outline.api.model.TransferMetricsResponse
+import org.sirekanyan.outline.ext.logDebug
 
 class OutlineApi {
 
@@ -49,7 +49,7 @@ class OutlineApi {
         try {
             httpClient.get("$apiUrl/metrics/transfer").body()
         } catch (exception: Exception) {
-            Log.d("OUTLINE", "Cannot fetch transfer metrics", exception)
+            logDebug("Cannot fetch transfer metrics", exception)
             null
         }
 

+ 21 - 0
app/src/main/java/org/sirekanyan/outline/ext/Logger.kt

@@ -0,0 +1,21 @@
+package org.sirekanyan.outline.ext
+
+import android.util.Log
+import org.sirekanyan.outline.CrashReporter
+
+private const val TAG = "Outline"
+
+fun logDebug(message: String, throwable: Throwable?) {
+    CrashReporter.handleException(throwable ?: Exception(message))
+    Log.d(TAG, message, throwable)
+}
+
+fun logWarn(message: String, throwable: Throwable?) {
+    CrashReporter.handleException(throwable ?: Exception(message))
+    Log.w(TAG, message, throwable)
+}
+
+fun logError(message: String, throwable: Throwable?) {
+    CrashReporter.handleException(throwable ?: Exception(message))
+    Log.e(TAG, message, throwable)
+}

+ 2 - 3
app/src/main/java/org/sirekanyan/outline/ext/PackageManager.kt

@@ -6,7 +6,6 @@ import android.content.Intent.ACTION_VIEW
 import android.content.pm.PackageManager.GET_ACTIVITIES
 import android.content.pm.PackageManager.NameNotFoundException
 import android.net.Uri
-import android.util.Log
 import android.widget.Toast
 
 private const val OUTLINE_PACKAGE = "org.outline.android.client"
@@ -29,7 +28,7 @@ fun openOutline(context: Context) {
             context.startActivity(intent)
         }
     } catch (exception: Exception) {
-        Log.d("OUTLINE", "Cannot open Outline", exception)
+        logDebug("Cannot open Outline", exception)
         openGooglePlay(context)
     }
 }
@@ -38,7 +37,7 @@ fun openGooglePlay(context: Context) {
     try {
         context.startActivity(Intent(ACTION_VIEW, Uri.parse(OUTLINE_PLAY_LINK)))
     } catch (exception: Exception) {
-        Log.d("OUTLINE", "Cannot open Google Play", exception)
+        logDebug("Cannot open Google Play", exception)
         Toast.makeText(context, "Cannot open Google Play", Toast.LENGTH_SHORT).show()
     }
 }

+ 2 - 2
app/src/main/java/org/sirekanyan/outline/repository/ServerRepository.kt

@@ -1,9 +1,9 @@
 package org.sirekanyan.outline.repository
 
 import android.net.Uri
-import android.util.Log
 import org.sirekanyan.outline.api.OutlineApi
 import org.sirekanyan.outline.api.model.Server
+import org.sirekanyan.outline.ext.logDebug
 import java.util.concurrent.ConcurrentHashMap
 
 class ServerRepository(private val api: OutlineApi) {
@@ -23,7 +23,7 @@ class ServerRepository(private val api: OutlineApi) {
             try {
                 return fetchServer(apiUrl)
             } catch (exception: Exception) {
-                Log.d("OUTLINE", "Cannot fetch server name", exception)
+                logDebug("Cannot fetch server name", exception)
             }
         }
         return getCachedServer(apiUrl)