Updated on 2026-08-14
This commit is contained in:
parent
6af3bb18e4
commit
3f2373bca7
4 changed files with 145 additions and 0 deletions
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.tangem.tap.common.log
|
||||||
|
|
||||||
|
import com.tangem.Log
|
||||||
|
import com.tangem.LogFormat
|
||||||
|
import com.tangem.TangemSdkLogger
|
||||||
|
import com.tangem.domain.settings.repositories.SettingsRepository
|
||||||
|
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.sync.Mutex
|
||||||
|
import kotlinx.coroutines.sync.withLock
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CardSDK logger implementation
|
||||||
|
*
|
||||||
|
* @property levels logging levels
|
||||||
|
* @property messageFormatter message formatter
|
||||||
|
* @property settingsRepository settings repository
|
||||||
|
* @property dispatchers coroutine dispatchers provider
|
||||||
|
*
|
||||||
|
[REDACTED_AUTHOR]
|
||||||
|
*/
|
||||||
|
internal class TangemCardSDKLogger(
|
||||||
|
private val levels: List<Log.Level>,
|
||||||
|
private val messageFormatter: LogFormat,
|
||||||
|
private val settingsRepository: SettingsRepository,
|
||||||
|
private val dispatchers: CoroutineDispatcherProvider,
|
||||||
|
) : TangemSdkLogger {
|
||||||
|
|
||||||
|
private val scope = CoroutineScope(dispatchers.main)
|
||||||
|
private val mutex = Mutex()
|
||||||
|
|
||||||
|
override fun log(message: () -> String, level: Log.Level) {
|
||||||
|
if (!levels.contains(level)) return
|
||||||
|
|
||||||
|
scope.launch(dispatchers.main) {
|
||||||
|
mutex.withLock {
|
||||||
|
settingsRepository.updateAppLogs(message = messageFormatter.format(message, level))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.tangem.tap.data
|
||||||
|
|
||||||
|
import com.tangem.blockchain.common.logging.BlockchainSDKLogger
|
||||||
|
import com.tangem.domain.settings.repositories.SettingsRepository
|
||||||
|
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.sync.Mutex
|
||||||
|
import kotlinx.coroutines.sync.withLock
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BlockchainSDK logger implementation
|
||||||
|
*
|
||||||
|
* @property settingsRepository settings repository
|
||||||
|
* @property dispatchers coroutine dispatchers provider
|
||||||
|
*
|
||||||
|
[REDACTED_AUTHOR]
|
||||||
|
*/
|
||||||
|
internal class TangemBlockchainSDKLogger(
|
||||||
|
private val settingsRepository: SettingsRepository,
|
||||||
|
private val dispatchers: CoroutineDispatcherProvider,
|
||||||
|
) : BlockchainSDKLogger {
|
||||||
|
|
||||||
|
private val scope = CoroutineScope(dispatchers.main)
|
||||||
|
private val mutex = Mutex()
|
||||||
|
|
||||||
|
override fun log(level: BlockchainSDKLogger.Level, message: String) {
|
||||||
|
scope.launch(dispatchers.main) {
|
||||||
|
mutex.withLock {
|
||||||
|
settingsRepository.updateAppLogs(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.tangem.tap.di.data
|
||||||
|
|
||||||
|
import com.tangem.blockchain.common.logging.BlockchainSDKLogger
|
||||||
|
import com.tangem.domain.settings.repositories.SettingsRepository
|
||||||
|
import com.tangem.tap.data.TangemBlockchainSDKLogger
|
||||||
|
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Module
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
internal object BlockchainSDKLoggerModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideBlockchainSDKLogger(
|
||||||
|
settingsRepository: SettingsRepository,
|
||||||
|
dispatchers: CoroutineDispatcherProvider,
|
||||||
|
): BlockchainSDKLogger {
|
||||||
|
return TangemBlockchainSDKLogger(settingsRepository, dispatchers)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.tangem.tap.di.data
|
||||||
|
|
||||||
|
import com.tangem.Log
|
||||||
|
import com.tangem.LogFormat
|
||||||
|
import com.tangem.TangemSdkLogger
|
||||||
|
import com.tangem.domain.settings.repositories.SettingsRepository
|
||||||
|
import com.tangem.tap.common.log.TangemCardSDKLogger
|
||||||
|
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Module
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
internal object CardSDKLoggerModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideCardSDKLogger(
|
||||||
|
settingsRepository: SettingsRepository,
|
||||||
|
dispatchers: CoroutineDispatcherProvider,
|
||||||
|
): TangemSdkLogger {
|
||||||
|
val logLevels = listOf(
|
||||||
|
Log.Level.ApduCommand,
|
||||||
|
Log.Level.Apdu,
|
||||||
|
Log.Level.Tlv,
|
||||||
|
Log.Level.Nfc,
|
||||||
|
Log.Level.Command,
|
||||||
|
Log.Level.Session,
|
||||||
|
Log.Level.View,
|
||||||
|
Log.Level.Network,
|
||||||
|
Log.Level.Error,
|
||||||
|
)
|
||||||
|
|
||||||
|
return TangemCardSDKLogger(
|
||||||
|
levels = logLevels,
|
||||||
|
messageFormatter = LogFormat.StairsFormatter(),
|
||||||
|
settingsRepository = settingsRepository,
|
||||||
|
dispatchers = dispatchers,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue