Reuse old log handler

This commit is contained in:
Ben Sarmiento
2024-02-01 00:41:04 +01:00
parent 6d39ec8e05
commit fc233686b1

View File

@@ -1,7 +1,6 @@
package logutil
import (
"bufio"
"bytes"
"fmt"
"io"
@@ -110,24 +109,10 @@ func (l *Logger) GetLogsFromFile() (string, error) {
return "", err
}
defer file.Close()
const maxLines = 100000
var lines []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
lines = append(lines, scanner.Text())
if len(lines) > maxLines {
lines = lines[1:]
}
}
if err := scanner.Err(); err != nil {
return "", err
}
var buffer bytes.Buffer
for _, line := range lines {
buffer.WriteString(line + "\n")
_, err = io.Copy(&buffer, file)
if err != nil {
return "", err
}
return buffer.String(), nil