Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.simprints.feature.troubleshooting.overview

import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.View
import androidx.core.content.FileProvider
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import com.simprints.feature.troubleshooting.R
Expand Down Expand Up @@ -68,6 +70,9 @@ internal class OverviewFragment : Fragment(R.layout.fragment_troubleshooting_ove
binding.troubleshootOverviewPing.setOnClickListener {
viewModel.pingServer()
}

// Log export is only Available starting from Android 8
binding.troubleshootOverviewExportLogsBlock.isVisible = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
binding.troubleshootOverviewExportLogs.setOnClickListener { v ->
viewModel.exportLogs()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
android:textIsSelectable="true" />

<LinearLayout
android:id="@+id/troubleshootOverviewExportLogsBlock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="16dp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.simprints.infra.logging

import android.content.Context
import android.os.Build
import co.touchlab.kermit.LogcatWriter
import co.touchlab.kermit.Logger
import co.touchlab.kermit.Severity
Expand All @@ -12,21 +13,29 @@ import com.simprints.infra.logging.writers.FileLogWriter

object SimberBuilder {
/**
* Simber needs to be initialized with the application context. It can be initialized multiple
* times without issue. Re-initializing Simber uproots and replants all trees.
* @param context Application Context
* Initializes the Simber logging framework with appropriate writers and severity based on build type.
*
* - Debug builds use `LogcatWriter` with `Severity.Debug`.
* - Release builds use `AnalyticsPropertyLogWriter` and `CrashlyticsLogWriter` with `Severity.Info`.
* - `FileLogWriter` is added for Android versions starting from API26.
*/
fun initialize(context: Context) {
if (BuildConfig.DEBUG) {
Logger.setLogWriters(LogcatWriter())
Logger.setMinSeverity(Severity.Debug)
} else {
Logger.setLogWriters(
when {
BuildConfig.DEBUG -> Logger.setLogWriters(LogcatWriter())

Build.VERSION.SDK_INT < Build.VERSION_CODES.O -> Logger.setLogWriters(
AnalyticsPropertyLogWriter(FirebaseAnalytics.getInstance(context)),
CrashlyticsLogWriter(FirebaseCrashlytics.getInstance()),
// Skip file logger to avoid crashes on Android 6-7 - https://simprints.atlassian.net/browse/MS-1060
)

else -> Logger.setLogWriters(
AnalyticsPropertyLogWriter(FirebaseAnalytics.getInstance(context)),
CrashlyticsLogWriter(FirebaseCrashlytics.getInstance()),
FileLogWriter(context),
)
Logger.setMinSeverity(Severity.Info)
}

Logger.setMinSeverity(if (BuildConfig.DEBUG) Severity.Debug else Severity.Info)
}
}