Implement logging module

This commit is contained in:
Kirill Kamakin
2022-08-05 18:58:21 +02:00
parent 057651c60f
commit ba5f7322ab
11 changed files with 207 additions and 3 deletions

View File

@@ -4,22 +4,23 @@ import gq.kirmanak.mealient.data.add.AddRecipeDataSource
import gq.kirmanak.mealient.data.add.models.AddRecipeRequest
import gq.kirmanak.mealient.data.network.ServiceFactory
import gq.kirmanak.mealient.extensions.logAndMapErrors
import timber.log.Timber
import gq.kirmanak.mealient.logging.Logger
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class AddRecipeDataSourceImpl @Inject constructor(
private val addRecipeServiceFactory: ServiceFactory<AddRecipeService>,
private val logger: Logger,
) : AddRecipeDataSource {
override suspend fun addRecipe(recipe: AddRecipeRequest): String {
Timber.v("addRecipe() called with: recipe = $recipe")
logger.v { "addRecipe() called with: recipe = $recipe" }
val service = addRecipeServiceFactory.provideService()
val response = logAndMapErrors(
block = { service.addRecipe(recipe) }, logProvider = { "addRecipe: can't add recipe" }
)
Timber.v("addRecipe() response = $response")
logger.v { "addRecipe() response = $response" }
return response
}
}