cleaner logging
This commit is contained in:
parent
1088fbac8b
commit
712b39ee0f
|
@ -17,21 +17,11 @@ func NewLogger() *Logger {
|
|||
|
||||
func (l *Logger) Log(line string) {
|
||||
l.lines = append(l.lines, fmt.Sprintf("%s: %s", time.Now().Format("15:04:05"), line))
|
||||
if len(l.lines) > 50 {
|
||||
l.lines = l.lines[1:]
|
||||
}
|
||||
}
|
||||
|
||||
func (l *Logger) Lines() []string {
|
||||
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
|
||||
return l.lines
|
||||
}
|
||||
|
|
|
@ -45,7 +45,6 @@ func (r *Runner) Init() {
|
|||
configTab := container.NewTabItem("config", configScreen.Content())
|
||||
r.screens = append(r.screens, configScreen)
|
||||
|
||||
r.logger.Log("initializing tasks...")
|
||||
tasks, err := component.NewTasks(r.conf)
|
||||
if err != nil {
|
||||
r.logger.Log(err.Error())
|
||||
|
@ -60,6 +59,7 @@ func (r *Runner) Init() {
|
|||
|
||||
r.fyneApp = fyneApp
|
||||
r.fyneWindow = w
|
||||
r.logger.Log("app started")
|
||||
|
||||
r.requests <- screen.SyncTasksRequest{}
|
||||
}
|
||||
|
@ -75,7 +75,6 @@ func (r *Runner) processRequest() {
|
|||
for req := range r.requests {
|
||||
switch v := req.(type) {
|
||||
case screen.SaveConfigRequest:
|
||||
r.logger.Log("saving new config...")
|
||||
r.status = "saving..."
|
||||
r.refresh <- true
|
||||
for k, val := range v.Fields {
|
||||
|
@ -85,22 +84,22 @@ func (r *Runner) processRequest() {
|
|||
r.status = "ready"
|
||||
r.refresh <- true
|
||||
case screen.SyncTasksRequest:
|
||||
r.logger.Log("syncing tasks...")
|
||||
r.status = "syncing..."
|
||||
r.refresh <- true
|
||||
countDisp, countFetch, err := r.tasks.Sync()
|
||||
if err != nil {
|
||||
r.logger.Log(err.Error())
|
||||
}
|
||||
r.logger.Log(fmt.Sprintf("dispatched: %d, fetched: %d", countDisp, countFetch))
|
||||
if countDisp > 0 || countFetch > 0 {
|
||||
r.logger.Log(fmt.Sprintf("task sync: dispatched: %d, fetched: %d", countDisp, countFetch))
|
||||
}
|
||||
r.status = "ready"
|
||||
r.refresh <- true
|
||||
case screen.MarkTaskDoneRequest:
|
||||
r.logger.Log(fmt.Sprintf("marking task %s done...", v.ID))
|
||||
if err := r.tasks.MarkDone(v.ID); err != nil {
|
||||
r.logger.Log(err.Error())
|
||||
}
|
||||
r.logger.Log("marked done")
|
||||
r.logger.Log(fmt.Sprintf("marked task %q done", v.ID))
|
||||
r.refresh <- true
|
||||
default:
|
||||
r.logger.Log("request unknown")
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package screen
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/data/binding"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
|
@ -17,7 +19,11 @@ func NewLog() *Log {
|
|||
}
|
||||
|
||||
func (l *Log) Refresh(state State) {
|
||||
l.lines.Set(state.Logs)
|
||||
lines := state.Logs
|
||||
sort.Slice(lines, func(i, j int) bool {
|
||||
return lines[i] > lines[j]
|
||||
})
|
||||
l.lines.Set(lines)
|
||||
}
|
||||
|
||||
func (l *Log) Content() fyne.CanvasObject {
|
||||
|
|
Loading…
Reference in New Issue