diff options
| author | Kujtim Hoxha <[email protected]> | 2025-04-09 19:07:39 +0200 |
|---|---|---|
| committer | Kujtim Hoxha <[email protected]> | 2025-04-09 19:07:39 +0200 |
| commit | d39d52d95d6aaab67fb3a17efb9ed62cc290e72f (patch) | |
| tree | 940bad6f0c847ceb213e5fc684b6d87cbf9d6996 /internal/logging/writer.go | |
| parent | 0d8d324ac6e640b95f4f2f62fd189399a959319a (diff) | |
| download | opencode-d39d52d95d6aaab67fb3a17efb9ed62cc290e72f.tar.gz opencode-d39d52d95d6aaab67fb3a17efb9ed62cc290e72f.zip | |
finish logs page
Diffstat (limited to 'internal/logging/writer.go')
| -rw-r--r-- | internal/logging/writer.go | 26 |
1 files changed, 18 insertions, 8 deletions
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) |
