fix(logger): invalid log format

This commit is contained in:
rhunk
2023-08-31 15:42:45 +02:00
parent dded6acff0
commit ea6260463c
2 changed files with 19 additions and 13 deletions

View File

@@ -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() {

View File

@@ -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)