Reuse old log handler
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user