Skip to content

Commit

Permalink
Ticket_28 : Replaced Timber with Napier
Browse files Browse the repository at this point in the history
  • Loading branch information
hojat72elect committed May 24, 2024
1 parent 6e7e166 commit 2b43a3f
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 25 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ https://user-images.githubusercontent.com/14782808/111520365-b187a880-8760-11eb-
for testing Room migrations.
- [MockWebServer](https://github.com/square/okhttp/tree/master/mockwebserver) - A scriptable web
server for testing HTTP clients.
- [Napier](https://github.com/AAkira/Napier) - Kotlin Multiplatform logging library.
- [Gradle's Kotlin DSL](https://docs.gradle.org/current/userguide/kotlin_dsl.html) - Gradle’s Kotlin
DSL is an alternative syntax to the Groovy DSL with an enhanced editing experience.
- [buildSrc](https://docs.gradle.org/current/userguide/organizing_gradle_projects.html#sec:build_sources)
Expand Down
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ dependencies {
implementation(AndroidX.browser)

// Logging
implementation(Tooling.timber)
implementation(Tooling.napier)

// Jetpack compose + Accompanist
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/ca/hojat/gamehub/GameHubApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import android.app.Application
import ca.hojat.gamehub.initializers.Initializer
import dagger.hilt.android.HiltAndroidApp
import javax.inject.Inject
import timber.log.Timber
import io.github.aakira.napier.DebugAntilog
import io.github.aakira.napier.Napier

@HiltAndroidApp
class GameHubApplication : Application() {
Expand All @@ -17,7 +18,7 @@ class GameHubApplication : Application() {

initializer.init()
if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
Napier.base(DebugAntilog())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.content.Intent
import android.net.Uri
import ca.hojat.gamehub.core.extensions.attachNewTaskFlagIfNeeded
import com.paulrybitskyi.hiltbinder.BindType
import timber.log.Timber
import io.github.aakira.napier.Napier
import javax.inject.Inject

@BindType(withQualifier = true)
Expand All @@ -19,7 +19,7 @@ internal class BrowserUrlOpener @Inject constructor() : UrlOpener {
context.startActivity(intent)
true
} catch (e: Exception) {
Timber.e(e)
Napier.e { e.toString() }
false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ca.hojat.gamehub.core.extensions.attachNewTaskFlagIfNeeded
import ca.hojat.gamehub.core.extensions.canUrlBeOpenedByNativeApp
import ca.hojat.gamehub.core.extensions.getNativeAppPackageForUrl
import com.paulrybitskyi.hiltbinder.BindType
import timber.log.Timber
import io.github.aakira.napier.Napier
import javax.inject.Inject

@BindType(withQualifier = true)
Expand All @@ -33,7 +33,7 @@ internal class NativeAppUrlOpener @Inject constructor() : UrlOpener {
context.startActivity(intent)
true
} catch (throwable: Throwable) {
Timber.e(throwable, "Wasn't able to start a native app for showing URL")
Napier.e(throwable) { "Wasn't able to start a native app for showing URL" }
false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import timber.log.Timber
import io.github.aakira.napier.Napier
import javax.inject.Inject

private const val PARAM_CATEGORY = "category"
Expand Down Expand Up @@ -94,7 +94,7 @@ internal class CategoryViewModel @Inject constructor(
.flowOn(dispatcherProvider.computation)
.map { items -> currentUiState.toSuccessState(items) }
.onError {
Timber.e(it, "Failed to observe ${categoryType.name} items.")
Napier.e(it){"Failed to observe ${categoryType.name} items."}
dispatchCommand(GeneralCommand.ShowLongToast(errorMapper.mapToMessage(it)))
emit(currentUiState.toEmptyState())
}
Expand Down Expand Up @@ -127,7 +127,7 @@ internal class CategoryViewModel @Inject constructor(
.resultOrError()
.map { currentUiState }
.onError {
Timber.e(it, "Failed to refresh ${categoryType.name} games.")
Napier.e(it) { "Failed to refresh ${categoryType.name} games." }
dispatchCommand(GeneralCommand.ShowLongToast(errorMapper.mapToMessage(it)))
}
.onStart {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.update
import timber.log.Timber
import io.github.aakira.napier.Napier
import javax.inject.Inject

/**
Expand Down Expand Up @@ -87,7 +87,7 @@ internal class DiscoverViewModel @Inject constructor(
transform = { it.toList() }
)
.map { listOfItems -> currentItems.toSuccessState(listOfItems) }
.onError { Timber.e(it, "Failed to observe games.") }
.onError { Napier.e(it) { "Failed to observe games." } }
.onStart { isObservingItems = true }
.onCompletion { isObservingItems = false }
.onEach { emittedItems -> _items.update { emittedItems } }
Expand All @@ -114,7 +114,7 @@ internal class DiscoverViewModel @Inject constructor(
)
.map { currentItems }
.onError {
Timber.e(it, "Failed to refresh games.")
Napier.e(it) { "Failed to refresh games." }
dispatchCommand(GeneralCommand.ShowLongToast(errorMapper.mapToMessage(it)))
}
.onStart {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import timber.log.Timber
import io.github.aakira.napier.Napier
import javax.inject.Inject

private const val PARAM_GAME_ID = "game-id"
Expand Down Expand Up @@ -80,7 +80,7 @@ internal class InfoScreenViewModel @Inject constructor(
.flowOn(dispatcherProvider.computation)
.map { game -> currentUiState.toSuccessState(game) }
.onError {
Timber.e(it, "Failed to load game info data.")
Napier.e(it) { "Failed to load game info data." }
dispatchCommand(GeneralCommand.ShowLongToast(errorMapper.mapToMessage(it)))
emit(currentUiState.toEmptyState())
}
Expand Down Expand Up @@ -120,7 +120,7 @@ internal class InfoScreenViewModel @Inject constructor(
)
.resultOrError()
.onError {
Timber.e(it, "Failed to get the image urls of type = $imageType.")
Napier.e(it) { "Failed to get the image urls of type = $imageType." }
dispatchCommand(GeneralCommand.ShowLongToast(errorMapper.mapToMessage(it)))
}
.collect { imageUrls ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import timber.log.Timber
import io.github.aakira.napier.Napier
import javax.inject.Inject

private const val SUBSEQUENT_EMISSION_DELAY = 500L
Expand Down Expand Up @@ -78,7 +78,7 @@ internal class LikesViewModel @Inject constructor(
.flowOn(dispatcherProvider.computation)
.map { games -> currentUiState.toSuccessState(games) }
.onError {
Timber.e(it, "Failed to load liked games.")
Napier.e(it) { "Failed to load liked games." }
dispatchCommand(GeneralCommand.ShowLongToast(errorMapper.mapToMessage(it)))
emit(currentUiState.toEmptyState())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.update
import timber.log.Timber
import io.github.aakira.napier.Napier
import javax.inject.Inject

private const val MAX_ARTICLE_COUNT = 100
Expand Down Expand Up @@ -74,7 +74,7 @@ internal class NewsViewModel @Inject constructor(
.flowOn(dispatcherProvider.computation)
.map { news -> currentUiState.toSuccessState(news) }
.onError {
Timber.e(it, "Failed to load articles.")
Napier.e(it) { "Failed to load articles." }
dispatchCommand(GeneralCommand.ShowLongToast(errorMapper.mapToMessage(it)))
emit(currentUiState.toEmptyState())
}
Expand All @@ -88,7 +88,7 @@ internal class NewsViewModel @Inject constructor(
}

fun onNewsItemClicked(model: NewsItemUiModel) {
Timber.d("link to the article => ${model.siteDetailUrl}")
Napier.d { "link to the article => ${model.siteDetailUrl}" }
navigateToArticleScreen(model)
}

Expand All @@ -103,7 +103,7 @@ internal class NewsViewModel @Inject constructor(
.resultOrError()
.map { currentUiState }
.onError {
Timber.e(it, "Failed to refresh articles.")
Napier.e(it) { "Failed to refresh articles." }
dispatchCommand(GeneralCommand.ShowLongToast(errorMapper.mapToMessage(it)))
}
.onStart {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import timber.log.Timber
import io.github.aakira.napier.Napier
import javax.inject.Inject
import kotlin.properties.Delegates
import kotlin.properties.ReadWriteProperty
Expand Down Expand Up @@ -157,7 +157,7 @@ internal class GamesSearchViewModel @Inject constructor(
)
}
.onError {
Timber.e(it, "Failed to search games.")
Napier.e(it) { "Failed to search games." }
dispatchCommand(GeneralCommand.ShowLongToast(errorMapper.mapToMessage(it)))
emit(createGamesEmptyUiState())
}
Expand Down
1 change: 0 additions & 1 deletion buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ object Tooling {
const val coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion"
const val coroutinesTest = "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion"

const val timber = "com.jakewharton.timber:timber:5.0.1"
const val napier = "io.github.aakira:napier:2.6.1"
}

Expand Down

0 comments on commit 2b43a3f

Please sign in to comment.