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