pretty listing of log data for testing

This commit is contained in:
Helmut Merz 2023-06-27 19:49:07 +02:00
parent 68f937042c
commit ea393bbb58
3 changed files with 32 additions and 13 deletions

View file

@ -1,9 +0,0 @@
package system
import "git.sr.ht/~cco/go-scopes/lib"
func RemoveFile(ctx lib.Context, fpath string) {
}
func RemoveFiles(ctx lib.Context, path, pattern string) {
}

View file

@ -1,6 +1,8 @@
package logging
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
@ -73,6 +75,18 @@ func GetLogger(ctx lib.Context) *Logger {
return globalLogger
}
// processing and printing of log data
func Parse(rec string) map[string]interface{} {
var buf map[string]interface{}
if err := json.Unmarshal([]byte(rec), &buf); err != nil {
fmt.Println("logging.Parse:", err)
}
return buf
}
// set up static data
func init() {
Levels["debug"] = DebugLevel
Levels["info"] = InfoLevel

View file

@ -60,15 +60,29 @@ func (t *T) TearDownApp() {
//t.AssertNoUncheckedMessages()
}
func (t *T) LogCount(pr bool) (count int) {
func (t *T) LogCount(pr bool) int {
count := 0
f, _ := os.Open("log/scopes.log")
defer f.Close()
scanner := bufio.NewScanner(f)
for scanner.Scan() {
if pr {
fmt.Println(scanner.Text())
}
count++
if pr {
txt := scanner.Text()
data := logging.Parse(txt)
level := data["level"]
message := data["message"]
delete(data, "level")
delete(data, "message")
delete(data, "time")
srv := "-"
if data["service"] != nil {
srv = data["service"].(string)
delete(data, "service")
}
fmt.Printf("%d: %s: %s - %s; %+v\n", count, level, srv, message, data)
//fmt.Println(scanner.Text())
}
}
return count
}