Skip to content

Commit

Permalink
Add Logging interface and apply log getter to that instead extension …
Browse files Browse the repository at this point in the history
…function to Any.

Add getLogger function to get logger if Interface is not used.
  • Loading branch information
HenrikJannsen committed Nov 26, 2024
1 parent 3eb65c5 commit 280acdc
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ import lombok.Getter
import lombok.Setter
import lombok.extern.slf4j.Slf4j
import network.bisq.mobile.android.node.service.AndroidMemoryReportService
import network.bisq.mobile.utils.log
import network.bisq.mobile.utils.Logging

import java.nio.file.Path
import java.util.Optional
import java.util.concurrent.CompletableFuture
Expand All @@ -57,7 +58,7 @@ import java.util.concurrent.TimeUnit
@Slf4j
@Getter
class AndroidApplicationService(androidMemoryReportService: AndroidMemoryReportService, userDataDir: Path?) :
ApplicationService("android", arrayOf<String>(), userDataDir) {
ApplicationService("android", arrayOf<String>(), userDataDir), Logging {

@Getter
class Supplier {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import bisq.user.identity.NymIdGenerator
import bisq.user.profile.UserProfile
import network.bisq.mobile.android.node.AndroidApplicationService
import network.bisq.mobile.domain.user_profile.UserProfileServiceFacade
import network.bisq.mobile.utils.log
import network.bisq.mobile.utils.Logging

import java.security.KeyPair
import java.util.Random
import kotlin.math.max
Expand All @@ -22,7 +23,7 @@ import kotlin.math.min
* Persistence is done inside the Bisq 2 libraries.
*/
class NodeUserProfileServiceFacade(private val supplier: AndroidApplicationService.Supplier) :
UserProfileServiceFacade {
UserProfileServiceFacade, Logging {

companion object {
private const val AVATAR_VERSION = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class NodeMainPresenter(
) : MainPresenter(applicationBootstrapFacade) {

override fun initializeServices() {
log.i{"initializeServices1"}
val context = (view as Activity).applicationContext
val filesDirsPath = (view as Activity).filesDir.toPath()
supplier.applicationService =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import network.bisq.mobile.client.replicated_model.user.identity.PreparedData
import network.bisq.mobile.client.replicated_model.user.profile.UserProfile
import network.bisq.mobile.client.user_profile.UserProfileResponse
import network.bisq.mobile.domain.user_profile.UserProfileServiceFacade
import network.bisq.mobile.utils.log
import network.bisq.mobile.utils.Logging
import kotlin.math.max
import kotlin.math.min
import kotlin.random.Random

class ClientUserProfileServiceFacade(private val apiGateway: UserProfileApiGateway) :
UserProfileServiceFacade {
UserProfileServiceFacade, Logging {

private var preparedData: PreparedData? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import kotlinx.coroutines.launch
import network.bisq.mobile.domain.data.BackgroundDispatcher
import network.bisq.mobile.domain.data.model.BaseModel
import network.bisq.mobile.domain.data.persistance.PersistenceSource
import network.bisq.mobile.utils.log
import network.bisq.mobile.utils.Logging


/**
* Repository implementation for a single object. Allows for persistance if the persistance source if provided, otherwise is mem-only.
Expand All @@ -18,7 +19,7 @@ import network.bisq.mobile.utils.log
*/
abstract class SingleObjectRepository<out T : BaseModel>(
private val persistenceSource: PersistenceSource<T>? = null
) : Repository<T> {
) : Repository<T>,Logging {

private val _data = MutableStateFlow<T?>(null)
override val data: StateFlow<T?> = _data
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package network.bisq.mobile.utils

import co.touchlab.kermit.Logger

private val loggerCache = mutableMapOf<String, Logger>()

interface Logging {
val log: Logger
get() {
return getLogger(this)
}
}

fun getLogger(anyObj: Any): Logger {
val tag = anyObj::class.simpleName
return if (tag != null) {
loggerCache.getOrPut(tag) { Logger.withTag(tag) }
} else {
// Anonymous classes or lambda expressions do not provide a simpleName
loggerCache.getOrPut("Default") { Logger }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package network.bisq.mobile.presentation

import androidx.annotation.CallSuper
import androidx.navigation.NavHostController
import co.touchlab.kermit.Logger
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
Expand All @@ -12,8 +11,8 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import network.bisq.mobile.domain.data.model.BaseModel
import network.bisq.mobile.presentation.ui.uicases.startup.SplashScreen
import network.bisq.mobile.utils.log
import network.bisq.mobile.utils.Logging


/**
* Presenter methods accesible by all views. Views should extend this interface when defining the behaviour expected for their presenter.
Expand Down Expand Up @@ -44,7 +43,7 @@ interface ViewPresenter {
* Base class allows to have a tree hierarchy of presenters. If the rootPresenter is null, this presenter acts as root
* if root present is passed, this present attach itself to the root to get updates (consequently its dependants will be always empty
*/
abstract class BasePresenter(private val rootPresenter: MainPresenter?): ViewPresenter {
abstract class BasePresenter(private val rootPresenter: MainPresenter?): ViewPresenter, Logging {
protected var view: Any? = null
// Coroutine scope for the presenter
protected val presenterScope = CoroutineScope(Dispatchers.Main + Job())
Expand Down Expand Up @@ -178,4 +177,4 @@ abstract class BasePresenter(private val rootPresenter: MainPresenter?): ViewPre
}

private fun isRoot() = rootPresenter == null
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package network.bisq.mobile.presentation

import androidx.navigation.NavHostController
import co.touchlab.kermit.Logger
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import network.bisq.mobile.android.node.BuildNodeConfig
import network.bisq.mobile.client.shared.BuildConfig
import network.bisq.mobile.domain.data.repository.main.bootstrap.ApplicationBootstrapFacade
import network.bisq.mobile.presentation.ui.AppPresenter
import network.bisq.mobile.utils.log


/**
* Main Presenter as an example of implementation for now.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import network.bisq.mobile.domain.user_profile.UserProfileServiceFacade
import network.bisq.mobile.presentation.BasePresenter
import network.bisq.mobile.presentation.MainPresenter
import network.bisq.mobile.presentation.ui.navigation.Routes
import network.bisq.mobile.utils.log


open class CreateProfilePresenter(
mainPresenter: MainPresenter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import network.bisq.mobile.domain.data.repository.main.bootstrap.ApplicationBoot
import network.bisq.mobile.presentation.BasePresenter
import network.bisq.mobile.presentation.MainPresenter
import network.bisq.mobile.presentation.ui.navigation.Routes
import network.bisq.mobile.utils.log


open class SplashPresenter(
mainPresenter: MainPresenter,
Expand Down

0 comments on commit 280acdc

Please sign in to comment.