Skip to content

Commit

Permalink
add ms to timestamp (#21)
Browse files Browse the repository at this point in the history
* add ms

* fix error printing
  • Loading branch information
DimaGolomozy authored Jun 10, 2024
1 parent 6f6e1cc commit 61ce46e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (manager *LoggerManager) AddLogLine(Severity uint, Text interface{}, Catego
}

NewLogRecord := Log{
float64(time.Now().Unix())*1000.0 + manager.TimeDelta,
float64(time.Now().UnixMilli()) + manager.TimeDelta,
Severity,
MessageToString(Text),
Category,
Expand Down
2 changes: 2 additions & 0 deletions slog_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ func (h *CoralogixHandler) Stop() {

func attrToMap(m map[string]any, a slog.Attr) {
switch v := a.Value.Any().(type) {
case error:
m[a.Key] = v.Error()
case []slog.Attr:
m2 := map[string]any{}
for _, a2 := range v {
Expand Down
7 changes: 5 additions & 2 deletions slog_handler_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package coralogix

import (
"errors"
"fmt"
"log/slog"
"strings"
Expand Down Expand Up @@ -29,10 +30,12 @@ func TestSlogHandler_AttrToMap(t *testing.T) {
m1 := map[string]any{}
attrToMap(m1, slog.String("1", "1"))
attrToMap(m1, slog.Int("2", 2))
attrToMap(m1, slog.Any("error", errors.New("test")))

assert.Equal(t, map[string]any{
"1": "1",
"2": int64(2),
"1": "1",
"2": int64(2),
"error": "test",
}, m1)

m2 := map[string]any{}
Expand Down

0 comments on commit 61ce46e

Please sign in to comment.