Skip to content

Commit

Permalink
use logging level setting to limit database writes for InAppLogger, r…
Browse files Browse the repository at this point in the history
…educe some logging.
  • Loading branch information
Ixam97 committed Jul 29, 2024
1 parent ef1a804 commit 0e29ba7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class CarDataSurfaceCallback(val carContext: CarContext): SurfaceCallback {

override fun onVisibleAreaChanged(visibleArea: Rect) {
synchronized(this) {
InAppLogger.i(
InAppLogger.d(
"[$TAG] Visible area changed " + surface + ". stableArea: "
+ stableArea + " visibleArea:" + visibleArea
)
Expand All @@ -82,7 +82,7 @@ class CarDataSurfaceCallback(val carContext: CarContext): SurfaceCallback {

override fun onStableAreaChanged(stableArea: Rect) {
synchronized(this) {
InAppLogger.i(
InAppLogger.d(
"[$TAG] Stable area changed " + surface + ". stableArea: "
+ stableArea + " visibleArea:" + visibleArea
)
Expand All @@ -98,14 +98,14 @@ class CarDataSurfaceCallback(val carContext: CarContext): SurfaceCallback {
renderFrame(clearFrame = true)
}
rendererEnabled = false
InAppLogger.i("[$TAG] Renderer paused")
InAppLogger.d("[$TAG] Renderer paused")
}

fun resume() {
if (rendererEnabled) return
rendererEnabled = true
invalidatePlot()
InAppLogger.i("[$TAG] Renderer enabled")
InAppLogger.d("[$TAG] Renderer enabled")
}

fun isEnabled() = rendererEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ import com.ixam97.carStatsViewer.compose.screens.settingsScreens.AboutScreen
import com.ixam97.carStatsViewer.compose.screens.settingsScreens.AppearanceScreen
import com.ixam97.carStatsViewer.compose.screens.settingsScreens.ChangelogScreen
import com.ixam97.carStatsViewer.compose.screens.settingsScreens.GeneralSettingsScreen
import com.ixam97.carStatsViewer.compose.screens.settingsScreens.WebViewScreen
import com.ixam97.carStatsViewer.compose.theme.CarTheme

object SettingsScreens {
const val GENERAL = "General"
const val APPEARANCE = "Appearance"
const val ABOUT = "About"
const val ABOUT_CHANGELOG = "About_Changelog"
const val WEBVIEW = "WebView"
}

@Composable
Expand All @@ -55,7 +57,7 @@ fun SettingsScreen(viewModel: SettingsViewModel) {
content = { AppearanceScreen(viewModel = viewModel) }
),
SideTab(
tabTitle = "About CSV",
tabTitle = "About Car Stats Viewer",
route = SettingsScreens.ABOUT,
type = SideTab.Type.Tab,
content = { navController -> AboutScreen(navController = navController) }
Expand All @@ -65,7 +67,13 @@ fun SettingsScreen(viewModel: SettingsViewModel) {
route = SettingsScreens.ABOUT_CHANGELOG,
type = SideTab.Type.Detail,
content = { navController -> ChangelogScreen(navController = navController) }
)
),
SideTab(
tabTitle = "WebView Test",
route = SettingsScreens.WEBVIEW,
type = SideTab.Type.Tab,
content = { WebViewScreen() }
)
)

Column(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.ixam97.carStatsViewer.compose.screens.settingsScreens

import android.view.ViewGroup
import android.webkit.WebView
import androidx.compose.runtime.Composable
import androidx.compose.ui.viewinterop.AndroidView

@Composable
fun WebViewScreen() {
AndroidView(factory = {
WebView(it).apply {
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
}
}, update = {it.loadUrl("https://ixam97.de/CSV")})
}
Original file line number Diff line number Diff line change
Expand Up @@ -625,18 +625,18 @@ class DataProcessor {
// } else if ((!emulatorMode && timestampSynchronizer.getSystemTimeFromNanosTimestamp(carPropertiesData.CurrentPower.timestamp) < System.currentTimeMillis() - 500) || (emulatorMode && timestampSynchronizer.getSystemTimeFromNanosTimestamp(carPropertiesData.CurrentSpeed.timestamp) < System.currentTimeMillis() - 500)) {
// InAppLogger.w("[NEO] Power value is too old!")
} else {
InAppLogger.d("[CHARGING CURVE] Before time check: ")
InAppLogger.d("[CHARGING CURVE] SoC timestamp: ${carPropertiesData.BatteryLevel.timestamp}")
InAppLogger.d("[CHARGING CURVE] Power timestamp: ${carPropertiesData.CurrentPower.timestamp}")
// InAppLogger.d("[CHARGING CURVE] Before time check: ")
// InAppLogger.d("[CHARGING CURVE] SoC timestamp: ${carPropertiesData.BatteryLevel.timestamp}")
// InAppLogger.d("[CHARGING CURVE] Power timestamp: ${carPropertiesData.CurrentPower.timestamp}")
// while ((!emulatorMode && timestampSynchronizer.getSystemTimeFromNanosTimestamp(carPropertiesData.CurrentPower.timestamp) < System.currentTimeMillis() - 500) || (emulatorMode && timestampSynchronizer.getSystemTimeFromNanosTimestamp(carPropertiesData.CurrentSpeed.timestamp) < System.currentTimeMillis() - 500)) {
while ((!emulatorMode && carPropertiesData.CurrentPower.timestamp < System.nanoTime() - 500_000_000) || (emulatorMode && carPropertiesData.CurrentSpeed.timestamp < System.nanoTime() - 500_000_000)) {
InAppLogger.w("[NEO] Power value is too old!")
delay(250)
}

InAppLogger.d("[CHARGING CURVE] After time check: ")
InAppLogger.d("[CHARGING CURVE] SoC timestamp: ${carPropertiesData.BatteryLevel.timestamp}")
InAppLogger.d("[CHARGING CURVE] Power timestamp: ${carPropertiesData.CurrentPower.timestamp}")
// InAppLogger.d("[CHARGING CURVE] After time check: ")
// InAppLogger.d("[CHARGING CURVE] SoC timestamp: ${carPropertiesData.BatteryLevel.timestamp}")
// InAppLogger.d("[CHARGING CURVE] Power timestamp: ${carPropertiesData.CurrentPower.timestamp}")

val currentTime = System.currentTimeMillis()
// InAppLogger.d("Time delta: ${currentTime - lastChargingPointTime}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import kotlinx.coroutines.launch
import java.text.SimpleDateFormat

val AppPreferences.LogLevel: AppPreference<Int>
get() = AppPreference<Int>("preference_log_level", Log.VERBOSE, sharedPref)
get() = AppPreference<Int>("preference_log_level", Log.INFO, sharedPref)
val AppPreferences.LogLength: AppPreference<Int>
get() = AppPreference<Int>("preference_log_length", 4, sharedPref)

Expand Down Expand Up @@ -56,6 +56,9 @@ object InAppLogger {
val messageTime = SimpleDateFormat("dd.MM.yyyy HH:mm:ss.SSS").format(logTime)
Log.println(type,"InAppLogger:", "$messageTime ${typeSymbol(type)}: $message")

// respect the log level setting when writing to database to reduce stress.
if (type < CarStatsViewer.appPreferences.logLevel + 2) return

CoroutineScope(Dispatchers.IO).launch {
try {
val newLogEntry = LogEntry(
Expand Down

0 comments on commit 0e29ba7

Please sign in to comment.