Skip to content

Commit

Permalink
chore: inject debug loggers
Browse files Browse the repository at this point in the history
  • Loading branch information
pereyrarg11 committed Nov 25, 2023
1 parent f7dfcfb commit 92c2cd9
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.pereyrarg11.drinks.core.di

import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.analytics.ktx.analytics
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase
import dagger.Module
import dagger.Provides
Expand All @@ -15,4 +17,8 @@ object FirebaseModule {
@Provides
@Singleton
fun provideFirebaseAnalytics(): FirebaseAnalytics = Firebase.analytics

@Provides
@Singleton
fun provideFirebaseCrashlytics(): FirebaseCrashlytics = Firebase.crashlytics
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.pereyrarg11.drinks.core.di.logger

import com.pereyrarg11.drinks.core.logger.debug.CrashlyticsDebugLoggerFacade
import com.pereyrarg11.drinks.core.logger.debug.DebugLogger
import com.pereyrarg11.drinks.core.logger.debug.DebugLoggerMediator
import com.pereyrarg11.drinks.core.logger.debug.LogcatDebugLoggerFacade
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import dagger.multibindings.IntoSet

@Module
@InstallIn(SingletonComponent::class)
abstract class DebugModule {
@Binds
@IntoSet
abstract fun bindLogcatDebugLoggerFacade(
debugLoggerFacade: LogcatDebugLoggerFacade
): DebugLogger.Facade

@Binds
@IntoSet
abstract fun bindCrashlyticsDebugLoggerFacade(
debugLoggerFacade: CrashlyticsDebugLoggerFacade
): DebugLogger.Facade

@Binds
abstract fun bindDebugLogger(
debugLogger: DebugLoggerMediator
): DebugLogger
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.pereyrarg11.drinks.core.logger.debug

import com.google.firebase.crashlytics.FirebaseCrashlytics
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class CrashlyticsDebugLoggerFacade @Inject constructor(
private val firebaseCrashlytics: FirebaseCrashlytics,
) : DebugLogger.Facade {

override fun logMessage(tag: String, message: String) {
firebaseCrashlytics.log("$tag: $message")
}

override fun logMessage(tag: String, messageTemplate: () -> String) {
logMessage(tag, messageTemplate())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pereyrarg11.drinks.core.logger.debug

interface DebugLogger {
fun logMessage(tag: String, message: String)

fun logMessage(tag: String, messageTemplate: () -> String)

interface Facade : DebugLogger
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.pereyrarg11.drinks.core.logger.debug

import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class DebugLoggerMediator @Inject constructor(
private val facades: Set<@JvmSuppressWildcards DebugLogger.Facade>,
) : DebugLogger {

override fun logMessage(tag: String, message: String) {
facades.forEach { debugLogger ->
debugLogger.logMessage(tag, message)
}
}

override fun logMessage(tag: String, messageTemplate: () -> String) {
facades.forEach { debugLogger ->
debugLogger.logMessage(tag, messageTemplate)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.pereyrarg11.drinks.core.logger.debug

import android.util.Log
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class LogcatDebugLoggerFacade @Inject constructor() : DebugLogger.Facade {
override fun logMessage(tag: String, message: String) {
Log.d(tag, message)
}

override fun logMessage(tag: String, messageTemplate: () -> String) {
logMessage(tag, messageTemplate())
}
}

0 comments on commit 92c2cd9

Please sign in to comment.