pretty listing of log data for testing
This commit is contained in:
parent
68f937042c
commit
ea393bbb58
3 changed files with 32 additions and 13 deletions
|
@ -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) {
|
|
||||||
}
|
|
|
@ -1,6 +1,8 @@
|
||||||
package logging
|
package logging
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
@ -73,6 +75,18 @@ func GetLogger(ctx lib.Context) *Logger {
|
||||||
return globalLogger
|
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() {
|
func init() {
|
||||||
Levels["debug"] = DebugLevel
|
Levels["debug"] = DebugLevel
|
||||||
Levels["info"] = InfoLevel
|
Levels["info"] = InfoLevel
|
||||||
|
|
|
@ -60,15 +60,29 @@ func (t *T) TearDownApp() {
|
||||||
//t.AssertNoUncheckedMessages()
|
//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")
|
f, _ := os.Open("log/scopes.log")
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
scanner := bufio.NewScanner(f)
|
scanner := bufio.NewScanner(f)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
if pr {
|
|
||||||
fmt.Println(scanner.Text())
|
|
||||||
}
|
|
||||||
count++
|
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
|
return count
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue