diff options
| author | adamdottv <[email protected]> | 2025-05-13 13:08:43 -0500 |
|---|---|---|
| committer | adamdottv <[email protected]> | 2025-05-13 13:08:43 -0500 |
| commit | 01b6bf5bb7307246cb2cca7f1cbc8aba693941cc (patch) | |
| tree | f47f5aa2b323ce8fea55f6999308486ff790d26e /internal/logging | |
| parent | d8f3b606258a5655d73acc94d6cb37b421350817 (diff) | |
| download | opencode-01b6bf5bb7307246cb2cca7f1cbc8aba693941cc.tar.gz opencode-01b6bf5bb7307246cb2cca7f1cbc8aba693941cc.zip | |
chore: refactor db
Diffstat (limited to 'internal/logging')
| -rw-r--r-- | internal/logging/logging.go | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/internal/logging/logging.go b/internal/logging/logging.go index b42f7caf7..2ba426756 100644 --- a/internal/logging/logging.go +++ b/internal/logging/logging.go @@ -86,11 +86,10 @@ func (s *service) Create(ctx context.Context, timestamp time.Time, level, messag dbLog, err := s.db.CreateLog(ctx, db.CreateLogParams{ ID: uuid.New().String(), SessionID: sql.NullString{String: sessionID, Valid: sessionID != ""}, - Timestamp: timestamp.UnixMilli(), + Timestamp: timestamp.UTC().Format(time.RFC3339Nano), Level: level, Message: message, Attributes: attributesJSON, - CreatedAt: time.Now().UnixMilli(), }) if err != nil { @@ -135,10 +134,24 @@ func (s *service) fromDBItem(item db.Log) Log { log := Log{ ID: item.ID, SessionID: item.SessionID.String, - Timestamp: time.UnixMilli(item.Timestamp), Level: item.Level, Message: item.Message, - CreatedAt: time.UnixMilli(item.CreatedAt), + } + + // Parse timestamp from ISO string + timestamp, err := time.Parse(time.RFC3339Nano, item.Timestamp) + if err == nil { + log.Timestamp = timestamp + } else { + log.Timestamp = time.Now() // Fallback + } + + // Parse created_at from ISO string + createdAt, err := time.Parse(time.RFC3339Nano, item.CreatedAt) + if err == nil { + log.CreatedAt = createdAt + } else { + log.CreatedAt = time.Now() // Fallback } if item.Attributes.Valid && item.Attributes.String != "" { @@ -195,7 +208,7 @@ func (sw *slogWriter) Write(p []byte) (n int, err error) { parsedTime, timeErr = time.Parse(time.RFC3339, value) if timeErr != nil { slog.Error("Failed to parse time in slog writer", "value", value, "error", timeErr) - timestamp = time.Now() + timestamp = time.Now().UTC() hasTimestamp = true continue } |
