Skip to content

Commit

Permalink
Use extension property log from LogUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikJannsen committed Nov 25, 2024
1 parent 36c5a51 commit eed860f
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ import bisq.settings.SettingsService
import bisq.support.SupportService
import bisq.trade.TradeService
import bisq.user.UserService
import com.google.common.base.Preconditions
import lombok.Getter
import lombok.Setter
import lombok.extern.slf4j.Slf4j
import network.bisq.mobile.android.node.service.AndroidMemoryReportService
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import network.bisq.mobile.utils.log
import java.nio.file.Path
import java.util.Optional
import java.util.concurrent.CompletableFuture
Expand Down Expand Up @@ -104,10 +102,8 @@ class AndroidApplicationService(androidMemoryReportService: AndroidMemoryReportS
companion object {
const val STARTUP_TIMEOUT_SEC: Long = 300
const val SHUTDOWN_TIMEOUT_SEC: Long = 10
val log: Logger = LoggerFactory.getLogger(ApplicationService::class.java)
}

val state = Observable(State.INITIALIZE_APP)
private val shutDownErrorMessage = Observable<String>()
private val startupErrorMessage = Observable<String>()

Expand Down Expand Up @@ -198,11 +194,11 @@ class AndroidApplicationService(androidMemoryReportService: AndroidMemoryReportS
override fun initialize(): CompletableFuture<Boolean> {
var ts = System.currentTimeMillis()
pruneAllBackups().join()
log.info("pruneAllBackups took {} ms", System.currentTimeMillis() - ts)
log.i("pruneAllBackups took $(System.currentTimeMillis() - ts) ms", )

ts = System.currentTimeMillis()
readAllPersisted().join()
log.info("readAllPersisted took {} ms", System.currentTimeMillis() - ts)
log.i("readAllPersisted took $(System.currentTimeMillis() - ts) ms")

return securityService.initialize()
.thenCompose { result: Boolean? ->
Expand Down Expand Up @@ -233,17 +229,14 @@ class AndroidApplicationService(androidMemoryReportService: AndroidMemoryReportS
if (throwable == null) {
if (result != null && result) {
setState(State.APP_INITIALIZED)
log.info("ApplicationService initialized")
log.i("ApplicationService initialized")
return@handle true
} else {
startupErrorMessage.set("Initializing applicationService failed with result=false")
log.error(startupErrorMessage.get())
log.e(startupErrorMessage.get())
}
} else {
log.error(
"Initializing applicationService failed",
throwable
)
log.e("Initializing applicationService failed", throwable)
startupErrorMessage.set(ExceptionUtil.getRootCauseMessage(throwable))
}
setState(State.FAILED)
Expand All @@ -252,7 +245,7 @@ class AndroidApplicationService(androidMemoryReportService: AndroidMemoryReportS
}

override fun shutdown(): CompletableFuture<Boolean> {
log.info("shutdown")
log.i("shutdown")
// We shut down services in opposite order as they are initialized
// In case a shutdown method completes exceptionally we log the error and map the result to `false` to not
// interrupt the shutdown sequence.
Expand Down Expand Up @@ -323,17 +316,14 @@ class AndroidApplicationService(androidMemoryReportService: AndroidMemoryReportS
.handle { result: Boolean?, throwable: Throwable? ->
if (throwable == null) {
if (result != null && result) {
log.info("ApplicationService shutdown completed")
log.i("ApplicationService shutdown completed")
return@handle true
} else {
startupErrorMessage.set("Shutdown applicationService failed with result=false")
log.error(shutDownErrorMessage.get())
log.e(shutDownErrorMessage.get())
}
} else {
log.error(
"Shutdown applicationService failed",
throwable
)
log.e("Shutdown applicationService failed", throwable)
shutDownErrorMessage.set(ExceptionUtil.getRootCauseMessage(throwable))
}
false
Expand All @@ -342,17 +332,9 @@ class AndroidApplicationService(androidMemoryReportService: AndroidMemoryReportS
}
}

private fun setState(newState: State) {
Preconditions.checkArgument(
state.get().ordinal < newState.ordinal,
"New state %s must have a higher ordinal as the current state %s", newState, state.get()
)
state.set(newState)
log.info("New state {}", newState)
}

private fun logError(throwable: Throwable): Boolean {
log.error("Exception at shutdown", throwable)
log.e("Exception at shutdown", throwable)
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import bisq.security.pow.ProofOfWork
import bisq.user.UserService
import bisq.user.identity.NymIdGenerator
import bisq.user.profile.UserProfile
import co.touchlab.kermit.Logger
import network.bisq.mobile.android.node.AndroidApplicationService
import network.bisq.mobile.domain.user_profile.UserProfileServiceFacade
import network.bisq.mobile.utils.log
import java.security.KeyPair
import java.util.Random
import kotlin.math.max
Expand All @@ -28,8 +28,6 @@ class NodeUserProfileServiceFacade(private val supplier: AndroidApplicationServi
private const val AVATAR_VERSION = 0
}

private val log = Logger.withTag(this::class.simpleName ?: "NodeUserProfileServiceFacade")

private var pubKeyHash: ByteArray? = null
private var keyPair: KeyPair? = null
private var proofOfWork: ProofOfWork? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import io.ktor.client.request.setBody
import io.ktor.http.contentType

class ApiRequestService(val httpClient: HttpClient, host: String) {
private val log = Logger.withTag(this::class.simpleName ?: "ApiRequestService")

private var baseUrl = "http://$host:8082/api/v1/"

fun endpoint(path: String) = baseUrl + path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package network.bisq.mobile.domain.client.main.user_profile

import co.touchlab.kermit.Logger
import kotlinx.coroutines.delay
import kotlinx.datetime.Clock
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 kotlin.math.max
import kotlin.math.min
import kotlin.random.Random

class ClientUserProfileServiceFacade(private val apiGateway: UserProfileApiGateway) :
UserProfileServiceFacade {
private val log = Logger.withTag(this::class.simpleName ?: "UserProfileServiceFacade")

private var preparedData: PreparedData? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import network.bisq.mobile.client.user_profile.UserProfileResponse
class UserProfileApiGateway(
private val apiRequestService: ApiRequestService
) {
private val log = Logger.withTag(this::class.simpleName ?: "UserProfileApiGateway")
private val basePath = "user-identities"
suspend fun requestPreparedData(): PreparedData {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package network.bisq.mobile.domain.data.repository

import co.touchlab.kermit.Logger
import kotlinx.coroutines.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
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

/**
* Repository implementation for a single object. Allows for persistance if the persistance source if provided, otherwise is mem-only.
Expand All @@ -17,8 +20,6 @@ abstract class SingleObjectRepository<out T : BaseModel>(
private val persistenceSource: PersistenceSource<T>? = null
) : Repository<T> {

private val logger = Logger.withTag(this::class.simpleName ?: "SingleObjectRepository")

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

Expand Down Expand Up @@ -58,7 +59,7 @@ abstract class SingleObjectRepository<out T : BaseModel>(
persistenceSource?.clear()
scope.cancel()
} catch (e: Exception) {
logger.e("Failed to cancel repository coroutine scope", e)
log.e("Failed to cancel repository coroutine scope", e)
} finally {
_data.value = null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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

/**
* Presenter methods accesible by all views. Views should extend this interface when defining the behaviour expected for their presenter.
Expand Down Expand Up @@ -45,7 +46,6 @@ interface ViewPresenter {
*/
abstract class BasePresenter(private val rootPresenter: MainPresenter?): ViewPresenter {
protected var view: Any? = null
private val log = Logger.withTag(this::class.simpleName ?: "BasePresenter")
// Coroutine scope for the presenter
protected val presenterScope = CoroutineScope(Dispatchers.Main + Job())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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 All @@ -19,7 +20,6 @@ open class MainPresenter(private val applicationBootstrapFacade: ApplicationBoot
navController = controller
}

private val log = Logger.withTag(this::class.simpleName ?: "MainPresenter")
// Observable state
private val _isContentVisible = MutableStateFlow(false)
override val isContentVisible: StateFlow<Boolean> = _isContentVisible
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package network.bisq.mobile.presentation.ui.uicases.startup

import co.touchlab.kermit.Logger
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -11,14 +10,13 @@ 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,
private val userProfileService: UserProfileServiceFacade
) : BasePresenter(mainPresenter) {

private val log = Logger.withTag(this::class.simpleName ?: "CreateProfilePresenter")

private val _id = MutableStateFlow("")
val id: StateFlow<String> get() = _id
private fun setId(value: String) {
Expand Down

0 comments on commit eed860f

Please sign in to comment.