From 96fa5af2bf1c2076e03080f885fdac8bbd75340d Mon Sep 17 00:00:00 2001 From: Jannis Mattheis Date: Sat, 7 Oct 2023 14:24:23 +0200 Subject: [PATCH] Replace log usage everywhere --- .../com/github/gotify/MissedMessageUtil.kt | 4 ++-- .../com/github/gotify/NotificationSupport.kt | 6 +++--- .../main/kotlin/com/github/gotify/Utils.kt | 8 ++++---- .../kotlin/com/github/gotify/api/Callback.kt | 6 ++++-- .../kotlin/com/github/gotify/api/CertUtils.kt | 10 ++++++---- .../gotify/init/InitializationActivity.kt | 9 +++++---- .../com/github/gotify/log/LogsActivity.kt | 10 +++++++--- .../gotify/log/UncaughtExceptionHandler.kt | 6 +++--- .../com/github/gotify/login/LoginActivity.kt | 4 ++-- .../gotify/messages/MessagesActivity.kt | 13 +++++++------ .../messages/provider/MessageRequester.kt | 12 ++++++------ .../picasso/PicassoDataRequestHandler.kt | 4 ++-- .../github/gotify/picasso/PicassoHandler.kt | 4 ++-- .../gotify/service/WebSocketConnection.kt | 18 +++++++++--------- .../github/gotify/service/WebSocketService.kt | 19 ++++++++++--------- .../github/gotify/sharing/ShareActivity.kt | 6 +++--- 16 files changed, 75 insertions(+), 64 deletions(-) diff --git a/app/src/main/kotlin/com/github/gotify/MissedMessageUtil.kt b/app/src/main/kotlin/com/github/gotify/MissedMessageUtil.kt index 3a69759..52e1a0f 100644 --- a/app/src/main/kotlin/com/github/gotify/MissedMessageUtil.kt +++ b/app/src/main/kotlin/com/github/gotify/MissedMessageUtil.kt @@ -5,7 +5,7 @@ import com.github.gotify.api.ApiException import com.github.gotify.api.Callback import com.github.gotify.client.api.MessageApi import com.github.gotify.client.model.Message -import com.github.gotify.log.Log +import org.tinylog.kotlin.Logger internal class MissedMessageUtil(private val api: MessageApi) { fun lastReceivedMessage(acceptID: (Long) -> Unit) { @@ -41,7 +41,7 @@ internal class MissedMessageUtil(private val api: MessageApi) { since = pagedMessages.paging.since } } catch (e: ApiException) { - Log.e("cannot retrieve missing messages", e) + Logger.error(e, "cannot retrieve missing messages") } return result.reversed() } diff --git a/app/src/main/kotlin/com/github/gotify/NotificationSupport.kt b/app/src/main/kotlin/com/github/gotify/NotificationSupport.kt index dd27c22..c9f5800 100644 --- a/app/src/main/kotlin/com/github/gotify/NotificationSupport.kt +++ b/app/src/main/kotlin/com/github/gotify/NotificationSupport.kt @@ -10,7 +10,7 @@ import android.os.Build import androidx.annotation.RequiresApi import androidx.preference.PreferenceManager import com.github.gotify.client.model.Application -import com.github.gotify.log.Log +import org.tinylog.kotlin.Logger internal object NotificationSupport { @RequiresApi(Build.VERSION_CODES.O) @@ -93,7 +93,7 @@ internal object NotificationSupport { notificationManager.createNotificationChannel(messagesImportanceDefault) notificationManager.createNotificationChannel(messagesImportanceHigh) } catch (e: Exception) { - Log.e("Could not create channel", e) + Logger.error(e, "Could not create channel") } } @@ -168,7 +168,7 @@ internal object NotificationSupport { notificationManager.createNotificationChannel(messagesImportanceDefault) notificationManager.createNotificationChannel(messagesImportanceHigh) } catch (e: Exception) { - Log.e("Could not create channel", e) + Logger.error(e, "Could not create channel") } } diff --git a/app/src/main/kotlin/com/github/gotify/Utils.kt b/app/src/main/kotlin/com/github/gotify/Utils.kt index 772d562..196d048 100644 --- a/app/src/main/kotlin/com/github/gotify/Utils.kt +++ b/app/src/main/kotlin/com/github/gotify/Utils.kt @@ -12,7 +12,6 @@ import android.view.View import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.lifecycleScope import com.github.gotify.client.JSON -import com.github.gotify.log.Log import com.google.android.material.snackbar.Snackbar import com.google.gson.Gson import com.squareup.picasso.Picasso.LoadedFrom @@ -31,6 +30,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import okio.Buffer import org.threeten.bp.OffsetDateTime +import org.tinylog.kotlin.Logger internal object Utils { val JSON: Gson = JSON().gson @@ -63,10 +63,10 @@ internal object Utils { URL(URL(baseURL), target).toString() } } catch (e: MalformedURLException) { - Log.e("Could not resolve absolute url", e) + Logger.error(e, "Could not resolve absolute url") target } catch (e: URISyntaxException) { - Log.e("Could not resolve absolute url", e) + Logger.error(e, "Could not resolve absolute url") target } } @@ -79,7 +79,7 @@ internal object Utils { } override fun onBitmapFailed(e: Exception, errorDrawable: Drawable) { - Log.e("Bitmap failed", e) + Logger.error(e, "Bitmap failed") } override fun onPrepareLoad(placeHolderDrawable: Drawable) {} diff --git a/app/src/main/kotlin/com/github/gotify/api/Callback.kt b/app/src/main/kotlin/com/github/gotify/api/Callback.kt index 0ef273c..5b0d0f1 100644 --- a/app/src/main/kotlin/com/github/gotify/api/Callback.kt +++ b/app/src/main/kotlin/com/github/gotify/api/Callback.kt @@ -1,7 +1,9 @@ package com.github.gotify.api import android.app.Activity -import com.github.gotify.log.Log +import com.github.gotify.api.Callback.ErrorCallback +import com.github.gotify.api.Callback.SuccessCallback +import org.tinylog.kotlin.Logger import retrofit2.Call import retrofit2.Response @@ -65,7 +67,7 @@ internal class Callback private constructor( private fun errorCallback(): Callback { return Callback( onSuccess = {}, - onError = { exception -> Log.e("Error while api call", exception) } + onError = { exception -> Logger.error(exception, "Error while api call") } ) } diff --git a/app/src/main/kotlin/com/github/gotify/api/CertUtils.kt b/app/src/main/kotlin/com/github/gotify/api/CertUtils.kt index 60a295b..ce0cb26 100644 --- a/app/src/main/kotlin/com/github/gotify/api/CertUtils.kt +++ b/app/src/main/kotlin/com/github/gotify/api/CertUtils.kt @@ -3,7 +3,6 @@ package com.github.gotify.api import android.annotation.SuppressLint import com.github.gotify.SSLSettings import com.github.gotify.Utils -import com.github.gotify.log.Log import java.io.IOException import java.security.GeneralSecurityException import java.security.KeyStore @@ -16,15 +15,18 @@ import javax.net.ssl.TrustManager import javax.net.ssl.TrustManagerFactory import javax.net.ssl.X509TrustManager import okhttp3.OkHttpClient +import org.tinylog.kotlin.Logger internal object CertUtils { @SuppressLint("CustomX509TrustManager") private val trustAll = object : X509TrustManager { @SuppressLint("TrustAllX509TrustManager") - override fun checkClientTrusted(chain: Array, authType: String) {} + override fun checkClientTrusted(chain: Array, authType: String) { + } @SuppressLint("TrustAllX509TrustManager") - override fun checkServerTrusted(chain: Array, authType: String) {} + override fun checkServerTrusted(chain: Array, authType: String) { + } override fun getAcceptedIssuers() = arrayOf() } @@ -62,7 +64,7 @@ internal object CertUtils { } } catch (e: Exception) { // We shouldn't have issues since the cert is verified on login. - Log.e("Failed to apply SSL settings", e) + Logger.error(e, "Failed to apply SSL settings") } } diff --git a/app/src/main/kotlin/com/github/gotify/init/InitializationActivity.kt b/app/src/main/kotlin/com/github/gotify/init/InitializationActivity.kt index c8b6de3..547185f 100644 --- a/app/src/main/kotlin/com/github/gotify/init/InitializationActivity.kt +++ b/app/src/main/kotlin/com/github/gotify/init/InitializationActivity.kt @@ -23,7 +23,6 @@ import com.github.gotify.api.Callback.SuccessCallback import com.github.gotify.api.ClientFactory import com.github.gotify.client.model.User import com.github.gotify.client.model.VersionInfo -import com.github.gotify.log.Log import com.github.gotify.log.LoggerHelper import com.github.gotify.log.UncaughtExceptionHandler import com.github.gotify.login.LoginActivity @@ -34,6 +33,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.livinglifetechway.quickpermissionskotlin.runWithPermissions import com.livinglifetechway.quickpermissionskotlin.util.QuickPermissionsOptions import com.livinglifetechway.quickpermissionskotlin.util.QuickPermissionsRequest +import org.tinylog.kotlin.Logger internal class InitializationActivity : AppCompatActivity() { @@ -61,7 +61,7 @@ internal class InitializationActivity : AppCompatActivity() { } UncaughtExceptionHandler.registerCurrentThread() settings = Settings(this) - Log.i("Entering ${javaClass.simpleName}") + Logger.info("Entering ${javaClass.simpleName}") installSplashScreen().setKeepOnScreenCondition { splashScreenActive } @@ -116,6 +116,7 @@ internal class InitializationActivity : AppCompatActivity() { dialog(getString(R.string.not_available, settings.url)) return } + 401 -> { dialog(getString(R.string.auth_failed)) return @@ -154,7 +155,7 @@ internal class InitializationActivity : AppCompatActivity() { } private fun authenticated(user: User) { - Log.i("Authenticated as ${user.name}") + Logger.info("Authenticated as ${user.name}") settings.setUser(user.name, user.isAdmin) requestVersion { @@ -173,7 +174,7 @@ internal class InitializationActivity : AppCompatActivity() { private fun requestVersion(runnable: Runnable) { requestVersion( callback = Callback.SuccessBody { version: VersionInfo -> - Log.i("Server version: ${version.version}@${version.buildDate}") + Logger.info("Server version: ${version.version}@${version.buildDate}") settings.serverVersion = version.version runnable.run() }, diff --git a/app/src/main/kotlin/com/github/gotify/log/LogsActivity.kt b/app/src/main/kotlin/com/github/gotify/log/LogsActivity.kt index d78dbc4..4fc0610 100644 --- a/app/src/main/kotlin/com/github/gotify/log/LogsActivity.kt +++ b/app/src/main/kotlin/com/github/gotify/log/LogsActivity.kt @@ -15,6 +15,7 @@ import com.github.gotify.Utils.launchCoroutine import com.github.gotify.databinding.ActivityLogsBinding import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext +import org.tinylog.kotlin.Logger internal class LogsActivity : AppCompatActivity() { @@ -25,7 +26,7 @@ internal class LogsActivity : AppCompatActivity() { super.onCreate(savedInstanceState) binding = ActivityLogsBinding.inflate(layoutInflater) setContentView(binding.root) - Log.i("Entering ${javaClass.simpleName}") + Logger.info("Entering ${javaClass.simpleName}") updateLogs() setSupportActionBar(binding.appBarDrawer.toolbar) val actionBar = supportActionBar @@ -37,7 +38,7 @@ internal class LogsActivity : AppCompatActivity() { private fun updateLogs() { launchCoroutine { - val log = Log.get() + val log = LoggerHelper.read(this) withContext(Dispatchers.Main) { val content = binding.logContent if (content.selectionStart == content.selectionEnd) { @@ -62,11 +63,13 @@ internal class LogsActivity : AppCompatActivity() { finish() true } + R.id.action_delete_logs -> { - Log.clear() + LoggerHelper.clear(this) binding.logContent.text = null true } + R.id.action_copy_logs -> { val content = binding.logContent val clipboardManager = @@ -76,6 +79,7 @@ internal class LogsActivity : AppCompatActivity() { Utils.showSnackBar(this, getString(R.string.logs_copied)) true } + else -> false } } diff --git a/app/src/main/kotlin/com/github/gotify/log/UncaughtExceptionHandler.kt b/app/src/main/kotlin/com/github/gotify/log/UncaughtExceptionHandler.kt index 024af8a..92aebca 100644 --- a/app/src/main/kotlin/com/github/gotify/log/UncaughtExceptionHandler.kt +++ b/app/src/main/kotlin/com/github/gotify/log/UncaughtExceptionHandler.kt @@ -1,11 +1,11 @@ package com.github.gotify.log -import com.github.gotify.log.Log.e +import org.tinylog.kotlin.Logger internal object UncaughtExceptionHandler { fun registerCurrentThread() { - Thread.setDefaultUncaughtExceptionHandler { _, e: Throwable? -> - e("uncaught exception", e!!) + Thread.setDefaultUncaughtExceptionHandler { _, e: Throwable -> + Logger.error(e, "uncaught exception") } } } diff --git a/app/src/main/kotlin/com/github/gotify/login/LoginActivity.kt b/app/src/main/kotlin/com/github/gotify/login/LoginActivity.kt index 77305c7..1f2d31e 100644 --- a/app/src/main/kotlin/com/github/gotify/login/LoginActivity.kt +++ b/app/src/main/kotlin/com/github/gotify/login/LoginActivity.kt @@ -27,13 +27,13 @@ import com.github.gotify.client.model.VersionInfo import com.github.gotify.databinding.ActivityLoginBinding import com.github.gotify.databinding.ClientNameDialogBinding import com.github.gotify.init.InitializationActivity -import com.github.gotify.log.Log import com.github.gotify.log.LogsActivity import com.github.gotify.log.UncaughtExceptionHandler import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.textfield.TextInputEditText import java.security.cert.X509Certificate import okhttp3.HttpUrl +import org.tinylog.kotlin.Logger internal class LoginActivity : AppCompatActivity() { private lateinit var binding: ActivityLoginBinding @@ -69,7 +69,7 @@ internal class LoginActivity : AppCompatActivity() { UncaughtExceptionHandler.registerCurrentThread() binding = ActivityLoginBinding.inflate(layoutInflater) setContentView(binding.root) - Log.i("Entering ${javaClass.simpleName}") + Logger.info("Entering ${javaClass.simpleName}") settings = Settings(this) } diff --git a/app/src/main/kotlin/com/github/gotify/messages/MessagesActivity.kt b/app/src/main/kotlin/com/github/gotify/messages/MessagesActivity.kt index ac49dd6..929fa70 100644 --- a/app/src/main/kotlin/com/github/gotify/messages/MessagesActivity.kt +++ b/app/src/main/kotlin/com/github/gotify/messages/MessagesActivity.kt @@ -45,7 +45,6 @@ import com.github.gotify.client.model.Client import com.github.gotify.client.model.Message import com.github.gotify.databinding.ActivityMessagesBinding import com.github.gotify.init.InitializationActivity -import com.github.gotify.log.Log import com.github.gotify.log.LogsActivity import com.github.gotify.login.LoginActivity import com.github.gotify.messages.provider.MessageState @@ -60,6 +59,7 @@ import com.google.android.material.snackbar.Snackbar import java.io.IOException import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext +import org.tinylog.kotlin.Logger internal class MessagesActivity : AppCompatActivity(), @@ -89,7 +89,7 @@ internal class MessagesActivity : binding = ActivityMessagesBinding.inflate(layoutInflater) setContentView(binding.root) viewModel = ViewModelProvider(this, MessagesModelFactory(this))[MessagesModel::class.java] - Log.i("Entering " + javaClass.simpleName) + Logger.info("Entering " + javaClass.simpleName) initDrawer() val layoutManager = LinearLayoutManager(this) @@ -132,6 +132,7 @@ internal class MessagesActivity : override fun onDrawerOpened(drawerView: View) { onBackPressedCallback.isEnabled = true } + override fun onDrawerClosed(drawerView: View) { updateAppOnDrawerClose?.let { selectApp -> updateAppOnDrawerClose = null @@ -175,7 +176,7 @@ internal class MessagesActivity : try { viewModel.picassoHandler.evict() } catch (e: IOException) { - Log.e("Problem evicting Picasso cache", e) + Logger.error(e, "Problem evicting Picasso cache") } startActivity(Intent(this, InitializationActivity::class.java)) finish() @@ -625,13 +626,13 @@ internal class MessagesActivity : } } if (currentClient != null) { - Log.i("Delete client with id " + currentClient.id) + Logger.info("Delete client with id " + currentClient.id) Api.execute(api.deleteClient(currentClient.id)) } else { - Log.e("Could not delete client, client does not exist.") + Logger.error("Could not delete client, client does not exist.") } } catch (e: ApiException) { - Log.e("Could not delete client", e) + Logger.error(e, "Could not delete client") } viewModel.settings.clear() diff --git a/app/src/main/kotlin/com/github/gotify/messages/provider/MessageRequester.kt b/app/src/main/kotlin/com/github/gotify/messages/provider/MessageRequester.kt index 973ea1f..d2eb3f2 100644 --- a/app/src/main/kotlin/com/github/gotify/messages/provider/MessageRequester.kt +++ b/app/src/main/kotlin/com/github/gotify/messages/provider/MessageRequester.kt @@ -6,31 +6,31 @@ import com.github.gotify.api.Callback import com.github.gotify.client.api.MessageApi import com.github.gotify.client.model.Message import com.github.gotify.client.model.PagedMessages -import com.github.gotify.log.Log +import org.tinylog.kotlin.Logger internal class MessageRequester(private val messageApi: MessageApi) { fun loadMore(state: MessageState): PagedMessages? { return try { - Log.i("Loading more messages for ${state.appId}") + Logger.info("Loading more messages for ${state.appId}") if (MessageState.ALL_MESSAGES == state.appId) { Api.execute(messageApi.getMessages(LIMIT, state.nextSince)) } else { Api.execute(messageApi.getAppMessages(state.appId, LIMIT, state.nextSince)) } } catch (apiException: ApiException) { - Log.e("failed requesting messages", apiException) + Logger.error(apiException, "failed requesting messages") null } } fun asyncRemoveMessage(message: Message) { - Log.i("Removing message with id ${message.id}") + Logger.info("Removing message with id ${message.id}") messageApi.deleteMessage(message.id).enqueue(Callback.call()) } fun deleteAll(appId: Long): Boolean { return try { - Log.i("Deleting all messages for $appId") + Logger.info("Deleting all messages for $appId") if (MessageState.ALL_MESSAGES == appId) { Api.execute(messageApi.deleteMessages()) } else { @@ -38,7 +38,7 @@ internal class MessageRequester(private val messageApi: MessageApi) { } true } catch (e: ApiException) { - Log.e("Could not delete messages", e) + Logger.error(e, "Could not delete messages") false } } diff --git a/app/src/main/kotlin/com/github/gotify/picasso/PicassoDataRequestHandler.kt b/app/src/main/kotlin/com/github/gotify/picasso/PicassoDataRequestHandler.kt index 14f0052..091fb6f 100644 --- a/app/src/main/kotlin/com/github/gotify/picasso/PicassoDataRequestHandler.kt +++ b/app/src/main/kotlin/com/github/gotify/picasso/PicassoDataRequestHandler.kt @@ -2,10 +2,10 @@ package com.github.gotify.picasso import android.graphics.BitmapFactory import android.util.Base64 -import com.github.gotify.log.Log import com.squareup.picasso.Picasso import com.squareup.picasso.Request import com.squareup.picasso.RequestHandler +import org.tinylog.kotlin.Logger /** * Adapted from https://github.com/square/picasso/issues/1395#issuecomment-220929377 By @@ -30,7 +30,7 @@ internal class PicassoDataRequestHandler : RequestHandler() { if (bitmap == null) { val show = if (uri.length > 50) uri.take(50) + "..." else uri val malformed = RuntimeException("Malformed data uri: $show") - Log.e("Could not load image", malformed) + Logger.error(malformed, "Could not load image") throw malformed } diff --git a/app/src/main/kotlin/com/github/gotify/picasso/PicassoHandler.kt b/app/src/main/kotlin/com/github/gotify/picasso/PicassoHandler.kt index 1a80bdb..0189d6a 100644 --- a/app/src/main/kotlin/com/github/gotify/picasso/PicassoHandler.kt +++ b/app/src/main/kotlin/com/github/gotify/picasso/PicassoHandler.kt @@ -8,13 +8,13 @@ import com.github.gotify.Settings import com.github.gotify.Utils import com.github.gotify.api.CertUtils import com.github.gotify.client.model.Application -import com.github.gotify.log.Log import com.squareup.picasso.OkHttp3Downloader import com.squareup.picasso.Picasso import java.io.File import java.io.IOException import okhttp3.Cache import okhttp3.OkHttpClient +import org.tinylog.kotlin.Logger internal class PicassoHandler(private val context: Context, private val settings: Settings) { companion object { @@ -52,7 +52,7 @@ internal class PicassoHandler(private val context: Context, private val settings Utils.resolveAbsoluteUrl("${settings.url}/", app.image) ) } catch (e: IOException) { - Log.e("Could not load image for notification", e) + Logger.error(e, "Could not load image for notification") } return BitmapFactory.decodeResource(context.resources, R.drawable.gotify) } diff --git a/app/src/main/kotlin/com/github/gotify/service/WebSocketConnection.kt b/app/src/main/kotlin/com/github/gotify/service/WebSocketConnection.kt index a92922b..6b14984 100644 --- a/app/src/main/kotlin/com/github/gotify/service/WebSocketConnection.kt +++ b/app/src/main/kotlin/com/github/gotify/service/WebSocketConnection.kt @@ -8,7 +8,6 @@ import com.github.gotify.SSLSettings import com.github.gotify.Utils import com.github.gotify.api.CertUtils import com.github.gotify.client.model.Message -import com.github.gotify.log.Log import java.util.Calendar import java.util.concurrent.TimeUnit import java.util.concurrent.atomic.AtomicLong @@ -18,6 +17,7 @@ import okhttp3.Request import okhttp3.Response import okhttp3.WebSocket import okhttp3.WebSocketListener +import org.tinylog.kotlin.Logger internal class WebSocketConnection( private val baseUrl: String, @@ -105,7 +105,7 @@ internal class WebSocketConnection( close() state = State.Connecting val nextId = ID.incrementAndGet() - Log.i("WebSocket($nextId): starting...") + Logger.info("WebSocket($nextId): starting...") webSocket = client.newWebSocket(request(), Listener(nextId)) return this @@ -116,7 +116,7 @@ internal class WebSocketConnection( if (webSocket != null) { webSocket?.close(1000, "") closed() - Log.i("WebSocket(${ID.get()}): closing existing connection.") + Logger.info("WebSocket(${ID.get()}): closing existing connection.") } } @@ -134,7 +134,7 @@ internal class WebSocketConnection( state = State.Scheduled if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - Log.i("WebSocket: scheduling a restart in $seconds second(s) (via alarm manager)") + Logger.info("WebSocket: scheduling a restart in $seconds second(s) (via alarm manager)") val future = Calendar.getInstance() future.add(Calendar.SECOND, seconds.toInt()) alarmManager.setExact( @@ -145,7 +145,7 @@ internal class WebSocketConnection( null ) } else { - Log.i("WebSocket: scheduling a restart in $seconds second(s)") + Logger.info("WebSocket: scheduling a restart in $seconds second(s)") reconnectHandler.removeCallbacks(reconnectCallback) reconnectHandler.postDelayed(reconnectCallback, TimeUnit.SECONDS.toMillis(seconds)) } @@ -155,7 +155,7 @@ internal class WebSocketConnection( override fun onOpen(webSocket: WebSocket, response: Response) { syncExec(id) { state = State.Connected - Log.i("WebSocket($id): opened") + Logger.info("WebSocket($id): opened") onOpen.run() if (errorCount > 0) { @@ -168,7 +168,7 @@ internal class WebSocketConnection( override fun onMessage(webSocket: WebSocket, text: String) { syncExec(id) { - Log.i("WebSocket($id): received message $text") + Logger.info("WebSocket($id): received message $text") val message = Utils.JSON.fromJson(text, Message::class.java) onMessageCallback(message) } @@ -178,7 +178,7 @@ internal class WebSocketConnection( override fun onClosed(webSocket: WebSocket, code: Int, reason: String) { syncExec(id) { if (state == State.Connected) { - Log.w("WebSocket($id): closed") + Logger.warn("WebSocket($id): closed") onClose.run() } closed() @@ -189,7 +189,7 @@ internal class WebSocketConnection( override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) { val code = if (response != null) "StatusCode: ${response.code()}" else "" val message = if (response != null) response.message() else "" - Log.e("WebSocket($id): failure $code Message: $message", t) + Logger.error(t) { "WebSocket($id): failure $code Message: $message" } syncExec(id) { closed() if (response != null && response.code() >= 400 && response.code() <= 499) { diff --git a/app/src/main/kotlin/com/github/gotify/service/WebSocketService.kt b/app/src/main/kotlin/com/github/gotify/service/WebSocketService.kt index b702c2d..8c0a5db 100644 --- a/app/src/main/kotlin/com/github/gotify/service/WebSocketService.kt +++ b/app/src/main/kotlin/com/github/gotify/service/WebSocketService.kt @@ -37,6 +37,7 @@ import com.github.gotify.picasso.PicassoHandler import io.noties.markwon.Markwon import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.atomic.AtomicLong +import org.tinylog.kotlin.Logger internal class WebSocketService : Service() { companion object { @@ -50,7 +51,7 @@ internal class WebSocketService : Service() { object : ConnectivityManager.NetworkCallback() { override fun onAvailable(network: Network) { super.onAvailable(network) - Log.i("WebSocket: Network available, reconnect if needed.") + Logger.info("WebSocket: Network available, reconnect if needed.") connection?.start() } } @@ -71,7 +72,7 @@ internal class WebSocketService : Service() { settings.token ) missingMessageUtil = MissedMessageUtil(client.createService(MessageApi::class.java)) - Log.i("Create ${javaClass.simpleName}") + Logger.info("Create ${javaClass.simpleName}") picassoHandler = PicassoHandler(this, settings) markwon = MarkwonFactory.createForNotification(this, picassoHandler.get()) } @@ -84,15 +85,15 @@ internal class WebSocketService : Service() { .unregisterNetworkCallback(networkCallback) } - Log.w("Destroy ${javaClass.simpleName}") + Logger.warn("Destroy ${javaClass.simpleName}") } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { LoggerHelper.init(this) - if (connection != null) { - connection!!.close() - } - Log.i("Starting ${javaClass.simpleName}") + UncaughtExceptionHandler.registerCurrentThread() + + connection?.close() + Logger.info("Starting ${javaClass.simpleName}") super.onStartCommand(intent, flags, startId) Thread { startPushService() }.start() @@ -168,7 +169,7 @@ internal class WebSocketService : Service() { getString(R.string.websocket_closed_logout) ) } else { - Log.i( + Logger.info( "WebSocket closed but the user still authenticated, " + "trying to reconnect" ) @@ -406,7 +407,7 @@ internal class WebSocketService : Service() { .bigPicture(picassoHandler.getImageFromUrl(notificationImageUrl)) ) } catch (e: Exception) { - Log.e("Error loading bigImageUrl", e) + Logger.error(e, "Error loading bigImageUrl") } } val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager diff --git a/app/src/main/kotlin/com/github/gotify/sharing/ShareActivity.kt b/app/src/main/kotlin/com/github/gotify/sharing/ShareActivity.kt index 167509e..6cd769d 100644 --- a/app/src/main/kotlin/com/github/gotify/sharing/ShareActivity.kt +++ b/app/src/main/kotlin/com/github/gotify/sharing/ShareActivity.kt @@ -18,10 +18,10 @@ import com.github.gotify.client.api.MessageApi import com.github.gotify.client.model.Application import com.github.gotify.client.model.Message import com.github.gotify.databinding.ActivityShareBinding -import com.github.gotify.log.Log import com.github.gotify.messages.provider.ApplicationHolder import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext +import org.tinylog.kotlin.Logger internal class ShareActivity : AppCompatActivity() { private lateinit var binding: ActivityShareBinding @@ -33,7 +33,7 @@ internal class ShareActivity : AppCompatActivity() { binding = ActivityShareBinding.inflate(layoutInflater) setContentView(binding.root) - Log.i("Entering ${javaClass.simpleName}") + Logger.info("Entering ${javaClass.simpleName}") setSupportActionBar(binding.appBarDrawer.toolbar) val actionBar = supportActionBar if (actionBar != null) { @@ -146,7 +146,7 @@ internal class ShareActivity : AppCompatActivity() { Api.execute(messageApi.createMessage(message)) true } catch (apiException: ApiException) { - Log.e("Failed sending message", apiException) + Logger.error(apiException, "Failed sending message") false } }