Skip to content

Commit

Permalink
Merge pull request #164 from niscy-eudiw/main
Browse files Browse the repository at this point in the history
New Logs mechanism with persistence storage caching and runtime logging, Implementation for logs retrieval throught the dashboard modal.
  • Loading branch information
stzouvaras authored Aug 2, 2024
2 parents baeacca + 77ee46d commit 5264ba8
Show file tree
Hide file tree
Showing 23 changed files with 331 additions and 103 deletions.
10 changes: 10 additions & 0 deletions assembly-logic/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@
android:theme="@style/Theme.EUDIWallet"
tools:targetApi="34">

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>

<service
android:name="eu.europa.ec.eudi.wallet.util.DefaultNfcEngagementService"
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package eu.europa.ec.assemblylogic
import android.app.Application
import eu.europa.ec.analyticslogic.controller.AnalyticsController
import eu.europa.ec.assemblylogic.di.setupKoin
import eu.europa.ec.businesslogic.controller.log.LogController
import eu.europa.ec.corelogic.config.WalletCoreConfig
import eu.europa.ec.eudi.wallet.EudiWallet
import eu.europa.ec.resourceslogic.theme.ThemeManager
Expand All @@ -31,7 +30,6 @@ import org.koin.android.ext.android.inject

class Application : Application() {

private val logController: LogController by inject()
private val configWalletCore: WalletCoreConfig by inject()
private val analyticsController: AnalyticsController by inject()

Expand All @@ -40,18 +38,13 @@ class Application : Application() {
setupKoin()
initializeReporting()
initializeEudiWallet()
initializeLogging()
initializeTheme()
}

private fun initializeReporting() {
analyticsController.initialize(this)
}

private fun initializeLogging() {
logController.install()
}

private fun initializeTheme() {
ThemeManager.Builder()
.withLightColors(ThemeColors.lightColors)
Expand Down
3 changes: 3 additions & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ dependencyResolutionManagement {
maven {
url = uri("https://plugins.gradle.org/m2/")
}
maven {
url = uri("https://jitpack.io")
}
}
versionCatalogs {
create("libs") {
Expand Down
4 changes: 2 additions & 2 deletions business-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ dependencies {
implementation(libs.gson)
implementation(libs.androidx.security)
implementation(libs.androidx.appAuth)
implementation(libs.logcat)
implementation(libs.google.phonenumber)
implementation(libs.rootbeer)
implementation(libs.timber)
implementation(libs.treessence)

testImplementation(project(LibraryModule.TestLogic.path))
androidTestImplementation(project(LibraryModule.TestLogic.path))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,63 +16,100 @@

package eu.europa.ec.businesslogic.controller.log

import eu.europa.ec.businesslogic.config.AppBuildType
import android.content.Context
import android.net.Uri
import android.util.Log
import androidx.core.content.FileProvider
import eu.europa.ec.businesslogic.config.ConfigLogic
import logcat.AndroidLogcatLogger
import logcat.LogPriority
import logcat.LogcatLogger
import logcat.asLog
import logcat.logcat
import fr.bipi.treessence.file.FileLoggerTree
import timber.log.Timber
import java.io.File

interface LogController {
fun install()
fun d(tag: String, message: () -> String)
fun d(message: () -> String)
fun e(tag: String, message: () -> String)
fun e(tag: String, exception: Throwable)
fun e(message: () -> String)
fun e(exception: Throwable)
fun w(tag: String, message: () -> String)
fun w(message: () -> String)
fun i(tag: String, message: () -> String)
fun i(message: () -> String)
fun retrieveLogFileUris(): List<Uri>
}

class LogControllerImpl(
private val context: Context,
configLogic: ConfigLogic
) : LogController {

private val flavorName = "EUDI Wallet"
private val appBuildType = configLogic.appBuildType
companion object {
private const val LOG_FILE_NAME = "eudi-android-wallet-logs%g.txt"
private const val FILE_SIZE_LIMIT = 5242880
private const val FILE_LIMIT = 10
}

override fun install() {
if (!LogcatLogger.isInstalled && AppBuildType.RELEASE != appBuildType) {
LogcatLogger.install(AndroidLogcatLogger(LogPriority.VERBOSE))
}
private val logsDir = File(context.filesDir.absolutePath + "/logs")

private val fileLoggerTree: FileLoggerTree = FileLoggerTree.Builder()
.withFileName(LOG_FILE_NAME)
.withDir(logsDir)
.withSizeLimit(FILE_SIZE_LIMIT)
.withFileLimit(FILE_LIMIT)
.withMinPriority(Log.DEBUG)
.appendToFile(true)
.build()

init {
Timber.plant(Timber.DebugTree(), fileLoggerTree)
}

private val tag: String = "EUDI Wallet ${configLogic.appFlavor}-${configLogic.appBuildType}"

override fun d(tag: String, message: () -> String) {
logcat(priority = LogPriority.DEBUG, tag = tag, message = message)
Timber.tag(tag).d(message())
}

override fun d(message: () -> String) {
d(tag = flavorName, message = message)
d(tag = tag, message = message)
}

override fun e(tag: String, message: () -> String) {
logcat(priority = LogPriority.ERROR, tag = tag, message = message)
Timber.tag(tag).e(message())
}

override fun e(tag: String, exception: Throwable) {
e(tag = tag, message = { exception.asLog() })
Timber.tag(tag).e(exception.message.orEmpty())
}

override fun e(message: () -> String) {
e(tag = flavorName, message = message)
e(tag, message)
}

override fun e(exception: Throwable) {
e(tag, exception)
}

override fun w(tag: String, message: () -> String) {
logcat(priority = LogPriority.WARN, tag = tag, message = message)
Timber.tag(tag).w(message())
}

override fun w(message: () -> String) {
w(tag = flavorName, message = message)
w(tag, message)
}

override fun i(tag: String, message: () -> String) {
Timber.tag(tag).i(message())
}

override fun i(message: () -> String) {
i(tag, message)
}

override fun retrieveLogFileUris(): List<Uri> {
return fileLoggerTree.files.map {
FileProvider.getUriForFile(context, "${context.packageName}.provider", it)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package eu.europa.ec.businesslogic.di

import android.content.Context
import eu.europa.ec.businesslogic.config.ConfigLogic
import eu.europa.ec.businesslogic.config.ConfigLogicImpl
import eu.europa.ec.businesslogic.controller.crypto.CryptoController
Expand Down Expand Up @@ -44,8 +45,8 @@ class LogicBusinessModule
fun provideConfigLogic(): ConfigLogic = ConfigLogicImpl()

@Single
fun provideLogController(configLogic: ConfigLogic): LogController =
LogControllerImpl(configLogic)
fun provideLogController(context: Context, configLogic: ConfigLogic): LogController =
LogControllerImpl(context, configLogic)

@Single
fun providePrefsController(resourceProvider: ResourceProvider): PrefsController =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ package eu.europa.ec.corelogic.config

import android.content.Context
import eu.europa.ec.corelogic.BuildConfig
import eu.europa.ec.corelogic.controller.WalletCoreLogController
import eu.europa.ec.eudi.wallet.EudiWalletConfig
import eu.europa.ec.eudi.wallet.issue.openid4vci.OpenId4VciManager
import eu.europa.ec.eudi.wallet.logging.Logger
import eu.europa.ec.eudi.wallet.transfer.openid4vp.ClientIdScheme
import eu.europa.ec.eudi.wallet.transfer.openid4vp.EncryptionAlgorithm
import eu.europa.ec.eudi.wallet.transfer.openid4vp.EncryptionMethod
import eu.europa.ec.eudi.wallet.transfer.openid4vp.PreregisteredVerifier
import eu.europa.ec.resourceslogic.R

internal class WalletCoreConfigImpl(
private val context: Context
private val context: Context,
private val walletCoreLogController: WalletCoreLogController
) : WalletCoreConfig {

private companion object {
Expand All @@ -46,7 +47,7 @@ internal class WalletCoreConfigImpl(
get() {
if (_config == null) {
_config = EudiWalletConfig.Builder(context)
.logLevel(Logger.OFF)
.logger(walletCoreLogController)
.userAuthenticationRequired(AUTHENTICATION_REQUIRED)
.openId4VpConfig {
withEncryptionAlgorithms(listOf(EncryptionAlgorithm.ECDH_ES))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ package eu.europa.ec.corelogic.config

import android.content.Context
import eu.europa.ec.corelogic.BuildConfig
import eu.europa.ec.corelogic.controller.WalletCoreLogController
import eu.europa.ec.eudi.wallet.EudiWalletConfig
import eu.europa.ec.eudi.wallet.issue.openid4vci.OpenId4VciManager
import eu.europa.ec.eudi.wallet.logging.Logger
import eu.europa.ec.eudi.wallet.transfer.openid4vp.ClientIdScheme
import eu.europa.ec.eudi.wallet.transfer.openid4vp.EncryptionAlgorithm
import eu.europa.ec.eudi.wallet.transfer.openid4vp.EncryptionMethod
import eu.europa.ec.eudi.wallet.transfer.openid4vp.PreregisteredVerifier
import eu.europa.ec.resourceslogic.R

internal class WalletCoreConfigImpl(
private val context: Context
private val context: Context,
private val walletCoreLogController: WalletCoreLogController
) : WalletCoreConfig {

private companion object {
Expand All @@ -46,7 +47,7 @@ internal class WalletCoreConfigImpl(
get() {
if (_config == null) {
_config = EudiWalletConfig.Builder(context)
.logLevel(Logger.LEVEL_DEBUG)
.logger(walletCoreLogController)
.userAuthenticationRequired(AUTHENTICATION_REQUIRED)
.openId4VpConfig {
withEncryptionAlgorithms(listOf(EncryptionAlgorithm.ECDH_ES))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2023 European Commission
*
* Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European
* Commission - subsequent versions of the EUPL (the "Licence"); You may not use this work
* except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the Licence for the specific language
* governing permissions and limitations under the Licence.
*/

package eu.europa.ec.corelogic.controller

import eu.europa.ec.businesslogic.controller.log.LogController
import eu.europa.ec.eudi.wallet.logging.Logger


interface WalletCoreLogController : Logger

class WalletCoreLogControllerImpl(
private val logController: LogController
) : WalletCoreLogController {

override fun log(record: Logger.Record) {
when (record.level) {
Logger.LEVEL_ERROR -> record.thrown?.let { logController.e(it) }
?: logController.e { record.message }

Logger.LEVEL_INFO -> logController.i { record.message }
Logger.LEVEL_DEBUG -> logController.d { record.message }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
package eu.europa.ec.corelogic.di

import android.content.Context
import eu.europa.ec.businesslogic.controller.log.LogController
import eu.europa.ec.corelogic.config.WalletCoreConfig
import eu.europa.ec.corelogic.config.WalletCoreConfigImpl
import eu.europa.ec.corelogic.controller.WalletCoreDocumentsController
import eu.europa.ec.corelogic.controller.WalletCoreDocumentsControllerImpl
import eu.europa.ec.corelogic.controller.WalletCoreLogController
import eu.europa.ec.corelogic.controller.WalletCoreLogControllerImpl
import eu.europa.ec.eudi.wallet.EudiWallet
import eu.europa.ec.resourceslogic.provider.ResourceProvider
import org.koin.core.annotation.ComponentScan
Expand All @@ -41,9 +44,14 @@ fun provideEudiWalletCore(): EudiWallet = EudiWallet

@Single
fun provideConfigWalletCore(
context: Context
context: Context,
walletCoreLogController: WalletCoreLogController
): WalletCoreConfig =
WalletCoreConfigImpl(context)
WalletCoreConfigImpl(context, walletCoreLogController)

@Single
fun provideWalletCoreLogController(logController: LogController): WalletCoreLogController =
WalletCoreLogControllerImpl(logController)

@Factory
fun provideWalletCoreDocumentsController(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package eu.europa.ec.dashboardfeature.di

import eu.europa.ec.businesslogic.config.ConfigLogic
import eu.europa.ec.businesslogic.controller.log.LogController
import eu.europa.ec.corelogic.config.WalletCoreConfig
import eu.europa.ec.corelogic.controller.WalletCoreDocumentsController
import eu.europa.ec.dashboardfeature.interactor.DashboardInteractor
Expand All @@ -35,11 +36,13 @@ fun provideDashboardInteractor(
resourceProvider: ResourceProvider,
walletCoreDocumentsController: WalletCoreDocumentsController,
walletCoreConfig: WalletCoreConfig,
configLogic: ConfigLogic
configLogic: ConfigLogic,
logController: LogController
): DashboardInteractor =
DashboardInteractorImpl(
resourceProvider,
walletCoreDocumentsController,
walletCoreConfig,
configLogic
configLogic,
logController
)
Loading

0 comments on commit 5264ba8

Please sign in to comment.