From d12b5498461cd808672d27fda7a1a324538f014a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paulo=20Sima=CC=83o?= Date: Mon, 11 Oct 2021 18:38:44 -0300 Subject: [PATCH] added log history --- api/replay/cli.go | 9 ++++++++- types/lib.go | 26 +++++++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/api/replay/cli.go b/api/replay/cli.go index 9e8ba53..91847f3 100644 --- a/api/replay/cli.go +++ b/api/replay/cli.go @@ -17,9 +17,16 @@ type Cli struct { func (c *Cli) Log(l *types.Log) error { l.Alias = c.ReplayEnvAlias() - l.Dtlog = time.Now() + l.Dtlogend = time.Now() 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 { return os.Getenv("REPLAY_QUEUEID") } diff --git a/types/lib.go b/types/lib.go index 539bcfc..dc5d48b 100644 --- a/types/lib.go +++ b/types/lib.go @@ -2,6 +2,7 @@ package types import ( "encoding/json" + "fmt" "strconv" "time" ) @@ -201,14 +202,25 @@ type Credentials struct { type Log struct { Model - Alias string `json:"alias,omitempty"` - Title string `json:"title,omitempty"` - Tags string `json:"tags,omitempty"` - Dtlog time.Time `json:"dtlog"` - Data []byte `json:"data,omitempty"` - Err string `json:"err,omitempty"` - Stack []byte `json:"stack,omitempty"` + Alias string `json:"alias,omitempty"` + Title string `json:"title,omitempty"` + Tags string `json:"tags,omitempty"` + Dtlog time.Time `json:"dtlog"` + Dtlogend time.Time `json:"dtlogend"` + Data []byte `json:"data,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 { From time.Time `json:"from"` Until time.Time `json:"until"`