From d39d52d95d6aaab67fb3a17efb9ed62cc290e72f Mon Sep 17 00:00:00 2001 From: Kujtim Hoxha Date: Wed, 9 Apr 2025 19:07:39 +0200 Subject: finish logs page --- internal/logging/writer.go | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'internal/logging/writer.go') diff --git a/internal/logging/writer.go b/internal/logging/writer.go index b4e899b30..9e597f5c9 100644 --- a/internal/logging/writer.go +++ b/internal/logging/writer.go @@ -10,15 +10,15 @@ import ( ) type writer struct { - messages []Message - *pubsub.Broker[Message] + messages []LogMessage + *pubsub.Broker[LogMessage] } func (w *writer) Write(p []byte) (int, error) { d := logfmt.NewDecoder(bytes.NewReader(p)) for d.ScanRecord() { - msg := Message{ - ID: time.Now().Format(time.RFC3339Nano), + msg := LogMessage{ + ID: fmt.Sprintf("%d", time.Now().UnixNano()), } for d.ScanKeyval() { switch string(d.Key()) { @@ -33,10 +33,20 @@ func (w *writer) Write(p []byte) (int, error) { case "msg": msg.Message = string(d.Value()) default: - msg.Attributes = append(msg.Attributes, Attr{ - Key: string(d.Key()), - Value: string(d.Value()), - }) + if string(d.Key()) == persistKeyArg { + msg.Persist = true + } else if string(d.Key()) == PersistTimeArg { + parsed, err := time.ParseDuration(string(d.Value())) + if err != nil { + continue + } + msg.PersistTime = parsed + } else { + msg.Attributes = append(msg.Attributes, Attr{ + Key: string(d.Key()), + Value: string(d.Value()), + }) + } } } w.messages = append(w.messages, msg) -- cgit v1.2.3 From 635324d386d52e117efea6fcbe9dbf306ec75653 Mon Sep 17 00:00:00 2001 From: Kujtim Hoxha Date: Wed, 9 Apr 2025 19:18:51 +0200 Subject: small fixes --- internal/logging/writer.go | 3 ++- internal/tui/components/core/status.go | 2 +- internal/tui/components/repl/sessions.go | 1 + internal/tui/tui.go | 3 +-- 4 files changed, 5 insertions(+), 4 deletions(-) (limited to 'internal/logging/writer.go') diff --git a/internal/logging/writer.go b/internal/logging/writer.go index 9e597f5c9..06a5330e3 100644 --- a/internal/logging/writer.go +++ b/internal/logging/writer.go @@ -18,7 +18,8 @@ func (w *writer) Write(p []byte) (int, error) { d := logfmt.NewDecoder(bytes.NewReader(p)) for d.ScanRecord() { msg := LogMessage{ - ID: fmt.Sprintf("%d", time.Now().UnixNano()), + ID: fmt.Sprintf("%d", time.Now().UnixNano()), + Time: time.Now(), } for d.ScanKeyval() { switch string(d.Key()) { diff --git a/internal/tui/components/core/status.go b/internal/tui/components/core/status.go index 6c4dda0a4..d2f14ad00 100644 --- a/internal/tui/components/core/status.go +++ b/internal/tui/components/core/status.go @@ -97,6 +97,6 @@ func (m statusCmp) model() string { func NewStatusCmp() tea.Model { return &statusCmp{ - messageTTL: 15 * time.Second, + messageTTL: 10 * time.Second, } } diff --git a/internal/tui/components/repl/sessions.go b/internal/tui/components/repl/sessions.go index 093337b18..d47c2a19e 100644 --- a/internal/tui/components/repl/sessions.go +++ b/internal/tui/components/repl/sessions.go @@ -123,6 +123,7 @@ func (i *sessionsCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case tea.KeyMsg: switch { case key.Matches(msg, sessionKeyMapValue.Select): + i.app.Logger.PersistInfo("Session selected") selected := i.list.SelectedItem() if selected == nil { return i, nil diff --git a/internal/tui/tui.go b/internal/tui/tui.go index c94a6b020..233b189dd 100644 --- a/internal/tui/tui.go +++ b/internal/tui/tui.go @@ -131,6 +131,7 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { TTL: msg.Payload.PersistTime, }) } + cmds = append(cmds, cmd) } case util.ClearStatusMsg: a.status, _ = a.status.Update(msg) @@ -205,8 +206,6 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } } - a.status, cmd = a.status.Update(msg) - cmds = append(cmds, cmd) if a.dialogVisible { d, cmd := a.dialog.Update(msg) a.dialog = d.(core.DialogCmp) -- cgit v1.2.3