commit ea6260463c8339800f252c7744f6bccc19c8ab55
parent dded6acff08dc925213bb7ab80a172d52da462e6
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date: Thu, 31 Aug 2023 15:42:45 +0200
fix(logger): invalid log format
Diffstat:
2 files changed, 19 insertions(+), 13 deletions(-)
diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/LogManager.kt b/app/src/main/kotlin/me/rhunk/snapenhance/LogManager.kt
@@ -44,18 +44,26 @@ class LogReader(
var lineCount = queryLineCount()
private fun readLogLine(): LogLine? {
- val lines = mutableListOf<String>()
+ val lines = StringBuilder()
+ val lastPointer = randomAccessFile.filePointer
+ var lastChar: Int = -1
+ var bufferLength = 0
while (true) {
- val lastPointer = randomAccessFile.filePointer
- val line = randomAccessFile.readLine() ?: return null
- if (lines.size > 0 && line.startsWith("|")) {
+ val char = randomAccessFile.read()
+ if (char == -1) {
randomAccessFile.seek(lastPointer)
+ return null
+ }
+ if ((char == '|'.code && lastChar == '\n'.code) || bufferLength > 4096) {
break
}
- lines.add(line)
+ lines.append(char.toChar())
+ bufferLength++
+ lastChar = char
}
- val line = lines.joinToString("\n").replaceFirst("|", "")
- return LogLine.fromString(line)
+
+ return LogLine.fromString(lines.trimEnd().toString())
+ ?: LogLine(LogLevel.ERROR, "1970-01-01 00:00:00", "LogReader", "Failed to parse log line: $lines")
}
fun incrementLineCount() {
diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/sections/home/HomeSubSection.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/sections/home/HomeSubSection.kt
@@ -128,7 +128,8 @@ class HomeSubSection(
.fillMaxSize()
) {
LazyColumn(
- modifier = Modifier.background(MaterialTheme.colorScheme.surfaceVariant),
+ modifier = Modifier.background(MaterialTheme.colorScheme.surface )
+ .horizontalScroll(ScrollState(0)),
state = logListState
) {
items(lineCount) { index ->
@@ -136,9 +137,6 @@ class HomeSubSection(
var expand by remember { mutableStateOf(false) }
Box(modifier = Modifier
.fillMaxWidth()
- .background(
- if (index % 2 == 0) MaterialTheme.colorScheme.surface else MaterialTheme.colorScheme.surfaceVariant
- )
.pointerInput(Unit) {
detectTapGestures(
onLongPress = {
@@ -154,8 +152,8 @@ class HomeSubSection(
Row(
modifier = Modifier
- .horizontalScroll(ScrollState(0))
.padding(4.dp)
+ .fillMaxWidth()
.defaultMinSize(minHeight = 30.dp),
verticalAlignment = Alignment.CenterVertically
) {
@@ -231,7 +229,7 @@ class HomeSubSection(
FilledIconButton(onClick = {
coroutineScope.launch {
- logListState.scrollToItem(logListState.layoutInfo.totalItemsCount - 1)
+ logListState.scrollToItem((logListState.layoutInfo.totalItemsCount - 1).takeIf { it >= 0 } ?: return@launch)
}
}) {
Icon(Icons.Filled.KeyboardDoubleArrowDown, contentDescription = null)