Log the SDK git Sha at application startup

Also improve the rendering of the log
This commit is contained in:
Benoit Marty
2026-08-28 12:02:18 +02:00
parent 4d12ec3682
commit 65878c6a34
4 changed files with 67 additions and 22 deletions
@@ -13,10 +13,14 @@ import androidx.compose.material3.ComposeMaterial3Flags.isAnchoredDraggableCompo
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.startup.AppInitializer
import androidx.work.Configuration
import dev.zacsweers.metro.Inject
import dev.zacsweers.metro.createGraphFactory
import io.element.android.libraries.architecture.bindings
import io.element.android.libraries.di.DependencyInjectionGraphOwner
import io.element.android.libraries.matrix.api.SdkMetadata
import io.element.android.libraries.workmanager.api.di.MetroWorkerFactory
import io.element.android.x.di.AppGraph
import io.element.android.x.di.ApplicationBindings
import io.element.android.x.info.logApplicationInfo
import io.element.android.x.initializer.CacheCleanerInitializer
import io.element.android.x.initializer.CrashInitializer
@@ -29,6 +33,8 @@ class ElementXApplication : Application(), DependencyInjectionGraphOwner, Config
.setWorkerFactory(MetroWorkerFactory(graph.workerProviders))
.build()
@Inject lateinit var sdkMetadata: SdkMetadata
@OptIn(ExperimentalMaterial3Api::class)
override fun onCreate() {
super.onCreate()
@@ -38,7 +44,8 @@ class ElementXApplication : Application(), DependencyInjectionGraphOwner, Config
initializeComponent(CacheCleanerInitializer::class.java)
}
logApplicationInfo(this)
bindings<ApplicationBindings>().inject(this)
logApplicationInfo(this, sdkMetadata.sdkGitSha)
// Disable the strict offset check for anchored draggable components, as it can cause issues with bottom sheets.
// Remove once https://issuetracker.google.com/issues/477038695 is fixed.
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2026 Element Creations Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
* Please see LICENSE files in the repository root for full details.
*/
package io.element.android.x.di
import dev.zacsweers.metro.AppScope
import dev.zacsweers.metro.ContributesTo
import io.element.android.x.ElementXApplication
@ContributesTo(AppScope::class)
interface ApplicationBindings {
fun inject(application: ElementXApplication)
}
@@ -10,32 +10,22 @@ package io.element.android.x.info
import android.content.Context
import io.element.android.libraries.androidutils.system.getVersionCodeFromManifest
import io.element.android.libraries.core.log.logger.wrapInBox
import io.element.android.x.BuildConfig
import timber.log.Timber
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
fun logApplicationInfo(context: Context) {
val appVersion = buildString {
append(BuildConfig.VERSION_NAME)
append(" (")
append(context.getVersionCodeFromManifest())
append(") - ")
append(BuildConfig.BUILD_TYPE)
append(" / ")
append(BuildConfig.FLAVOR)
}
// TODO Get SDK version somehow
val sdkVersion = "SDK VERSION (TODO)"
fun logApplicationInfo(context: Context, sdkGitSha: String) {
val appVersion = "${BuildConfig.VERSION_NAME} (${context.getVersionCodeFromManifest()}) - ${BuildConfig.BUILD_TYPE} / ${BuildConfig.FLAVOR}"
val date = SimpleDateFormat("MM-dd HH:mm:ss.SSSZ", Locale.US).format(Date())
Timber.d("----------------------------------------------------------------")
Timber.d("----------------------------------------------------------------")
Timber.d(" Application version: $appVersion")
Timber.d(" Git SHA: ${BuildConfig.GIT_REVISION}")
Timber.d(" SDK version: $sdkVersion")
Timber.d(" Local time: $date")
Timber.d("----------------------------------------------------------------")
Timber.d("----------------------------------------------------------------\n\n\n\n")
listOf(
" Application version: $appVersion",
" Element X: https://github.com/element-hq/element-x-android/commit/${BuildConfig.GIT_REVISION}",
" SDK : https://github.com/matrix-org/matrix-rust-sdk/commit/$sdkGitSha",
" Local time: $date",
)
.wrapInBox(minBoxInsideWidth = 80)
.forEach { Timber.d(it) }
}
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2026 Element Creations Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
* Please see LICENSE files in the repository root for full details.
*/
package io.element.android.libraries.core.log.logger
import kotlin.math.max
/**
* Wraps a list of strings in a box with borders.
* Allow to print pretty logs.
*
* @param minBoxInsideWidth The minimum width of the box inside, default is 80.
* @return A list of strings representing the boxed lines.
*/
fun List<String>.wrapInBox(
minBoxInsideWidth: Int = 80,
): List<String> {
val maxLength = maxOfOrNull { it.length } ?: 0
val boxWidth = max(maxLength, minBoxInsideWidth) + 4
val topBorder = "┌" + "─".repeat(boxWidth - 2) + "┐"
val bottomBorder = "└" + "─".repeat(boxWidth - 2) + "┘"
val boxedLines = map { line ->
val padding = " ".repeat(max(0, boxWidth - line.length - 4))
"│ $line$padding │"
}
return listOf(topBorder) + boxedLines + listOf(bottomBorder)
}