added log history

nats
Paulo Simão 2021-10-11 18:38:44 -03:00
parent 392c7940af
commit d12b549846
2 changed files with 27 additions and 8 deletions

View File

@ -17,9 +17,16 @@ type Cli struct {
func (c *Cli) Log(l *types.Log) error { func (c *Cli) Log(l *types.Log) error {
l.Alias = c.ReplayEnvAlias() l.Alias = c.ReplayEnvAlias()
l.Dtlog = time.Now() l.Dtlogend = time.Now()
return c.HttpCli().JsonPost("/api/v1/log/add", l, nil) return c.HttpCli().JsonPost("/api/v1/log/add", l, nil)
} }
func (c *Cli) NewLog() *types.Log {
ret := &types.Log{}
ret.Alias = c.ReplayEnvAlias()
ret.Dtlog = time.Now()
return ret
}
func (c *Cli) ReplayEnvQueueId() string { func (c *Cli) ReplayEnvQueueId() string {
return os.Getenv("REPLAY_QUEUEID") return os.Getenv("REPLAY_QUEUEID")
} }

View File

@ -2,6 +2,7 @@ package types
import ( import (
"encoding/json" "encoding/json"
"fmt"
"strconv" "strconv"
"time" "time"
) )
@ -201,14 +202,25 @@ type Credentials struct {
type Log struct { type Log struct {
Model Model
Alias string `json:"alias,omitempty"` Alias string `json:"alias,omitempty"`
Title string `json:"title,omitempty"` Title string `json:"title,omitempty"`
Tags string `json:"tags,omitempty"` Tags string `json:"tags,omitempty"`
Dtlog time.Time `json:"dtlog"` Dtlog time.Time `json:"dtlog"`
Data []byte `json:"data,omitempty"` Dtlogend time.Time `json:"dtlogend"`
Err string `json:"err,omitempty"` Data []byte `json:"data,omitempty"`
Stack []byte `json:"stack,omitempty"` Err string `json:"err,omitempty"`
History string `json:"history,omitempty"`
} }
func (l *Log) AddHistory(s string) {
s = fmt.Sprintf("* %s: %s", time.Now().Format("02/01/06 - 15:04:05"), s)
if l.History == "" {
l.History = s
} else {
l.History = l.History + "\n" + s
}
}
type LogQuery struct { type LogQuery struct {
From time.Time `json:"from"` From time.Time `json:"from"`
Until time.Time `json:"until"` Until time.Time `json:"until"`