gte/cmd/android-app/component/logger.go

38 lines
562 B
Go
Raw Normal View History

2022-10-18 16:58:12 +02:00
package component
2022-10-20 13:58:48 +02:00
import (
"fmt"
"time"
)
2022-10-18 16:58:12 +02:00
type Logger struct {
lines []string
}
func NewLogger() *Logger {
return &Logger{
lines: []string{},
}
}
func (l *Logger) Log(line string) {
2022-10-20 13:58:48 +02:00
l.lines = append(l.lines, fmt.Sprintf("%s: %s", time.Now().Format("15:04:05"), line))
2022-10-18 16:58:12 +02:00
}
func (l *Logger) Lines() []string {
2022-10-20 13:58:48 +02:00
if len(l.lines) == 0 {
return []string{}
}
last := len(l.lines) - 1
first := last - 50
if first < 0 {
first = 0
}
reverse := []string{}
for i := last; i >= first; i-- {
reverse = append(reverse, l.lines[i])
}
return reverse
2022-10-18 16:58:12 +02:00
}