74: Update logging to gather more information

This commit is contained in:
Ryan Harg 2021-08-13 10:55:26 +02:00 committed by Ryan Harg
parent fe1151444b
commit fe4a00ae07
5 changed files with 41 additions and 26 deletions

View File

@ -43,23 +43,20 @@ class LoginActivity : AppCompatActivity() {
data?.let {
when (requestCode) {
0 -> {
oAuth.exchange(this, data,
{
PowerPreference
.getFileByName(AppContext.PREFS_CREDENTIALS)
.setBoolean("anonymous", false)
oAuth.exchange(this, data) {
PowerPreference
.getFileByName(AppContext.PREFS_CREDENTIALS)
.setBoolean("anonymous", false)
lifecycleScope.launch(Main) {
Userinfo.get(this@LoginActivity, oAuth)?.let {
startActivity(Intent(this@LoginActivity, MainActivity::class.java))
lifecycleScope.launch(Main) {
Userinfo.get(this@LoginActivity, oAuth)?.let {
startActivity(Intent(this@LoginActivity, MainActivity::class.java))
return@launch finish()
}
throw Exception(getString(R.string.login_error_userinfo))
return@launch finish()
}
},
{ "error".log() }
)
throw Exception(getString(R.string.login_error_userinfo))
}
}
}
}
}

View File

@ -637,7 +637,7 @@ class MainActivity : AppCompatActivity() {
.body(Gson().toJson(mapOf("track" to track.id)))
.awaitStringResponse()
} catch (e: Exception) {
e.log()
e.logError("incrementListenCount()")
}
}
}

View File

@ -12,6 +12,7 @@ import android.media.MediaMetadata
import android.os.Build
import android.os.IBinder
import android.support.v4.media.MediaMetadataCompat
import android.util.Log
import android.view.KeyEvent
import androidx.core.app.NotificationManagerCompat
import androidx.media.session.MediaButtonReceiver
@ -479,7 +480,10 @@ class PlayerService : Service() {
super.onPositionDiscontinuity(reason)
if (reason == Player.DISCONTINUITY_REASON_PERIOD_TRANSITION) {
EventBus.send(Event.TrackFinished(queue.current()))
val currentTrack = queue.current().also {
it.log("Track finished")
}
EventBus.send(Event.TrackFinished(currentTrack))
}
}

View File

@ -60,7 +60,7 @@ class OAuth(private val authorizationServiceFactory: AuthorizationServiceFactory
} else {
false
}.also {
it.log("isAuthorized()")
it.logInfo("isAuthorized()")
}
}
@ -75,7 +75,7 @@ class OAuth(private val authorizationServiceFactory: AuthorizationServiceFactory
state: AuthState,
context: Context
): Boolean {
if (state.needsTokenRefresh.also { it.log("needsTokenRefresh()") } &&
if (state.needsTokenRefresh.also { it.logInfo("needsTokenRefresh()") } &&
state.refreshToken != null) {
val refreshRequest = state.createTokenRefreshRequest()
val auth = ClientSecretPost(state.clientSecret)
@ -91,7 +91,7 @@ class OAuth(private val authorizationServiceFactory: AuthorizationServiceFactory
}
return (state.isAuthorized)
.also {
it.log("tryRefreshAccessToken()")
it.logInfo("tryRefreshAccessToken()")
}
}
@ -171,8 +171,7 @@ class OAuth(private val authorizationServiceFactory: AuthorizationServiceFactory
fun exchange(
context: Context,
authorization: Intent,
success: () -> Unit,
error: () -> Unit
success: () -> Unit
) {
state().let { state ->
state.apply {
@ -194,7 +193,7 @@ class OAuth(private val authorizationServiceFactory: AuthorizationServiceFactory
}
if (response != null) success()
else error()
else Log.e("FFA", "performTokenRequest() not successful")
}
}
}

View File

@ -3,6 +3,8 @@ package audio.funkwhale.ffa.utils
import android.content.Context
import android.widget.Toast
import com.google.android.exoplayer2.util.Log
import com.google.android.exoplayer2.util.Log.LOG_LEVEL_ERROR
import com.google.android.exoplayer2.util.Log.LOG_LEVEL_INFO
import com.preference.PowerPreference
import java.net.URI
@ -31,10 +33,23 @@ private fun logClassName(): String {
return "UNKNOWN"
}
fun Any?.log(prefix: String? = null) {
prefix?.let {
Log.d("FFA", "${logClassName()} - $prefix: $this")
} ?: Log.d("FFA", "${logClassName()} - $this")
enum class LogLevel(value: Int) {
INFO(LOG_LEVEL_INFO),
DEBUG(Log.LOG_LEVEL_ALL),
ERROR(LOG_LEVEL_ERROR)
}
fun Any?.logError(prefix: String? = null) = this.log(prefix, LogLevel.ERROR)
fun Any?.logInfo(prefix: String? = null) = this.log(prefix, LogLevel.INFO)
fun Any?.log(prefix: String? = null, logLevel: LogLevel = LogLevel.DEBUG) {
val tag = "FFA"
val message = "${logClassName()} - ${prefix?.let { "$it: " }}$this"
when (logLevel) {
LogLevel.DEBUG -> Log.d(tag, message)
LogLevel.INFO -> Log.i(tag, message)
LogLevel.ERROR -> Log.e(tag, message)
}
}
fun maybeNormalizeUrl(rawUrl: String?): String? {