李伟乐 2 years ago
parent 5a24bd9053
commit 2103b6ae23
  1. 10
      log/mq/nsq.go
  2. 14
      log/mq/nsq_test.go

@ -79,13 +79,15 @@ func (l *nsqLogger) Log(level log.Level, keyvals ...any) error {
if len(keyvals)&1 == 1 {
keyvals = append(keyvals, "KEYVALS UNPAIRED")
}
buf := make(map[any]any)
buf := make(map[string]any)
buf["status"] = level.String()
for i := 0; i < len(keyvals); i += 2 {
buf[keyvals[i]] = keyvals[i+1]
buf[fmt.Sprintf("%v", keyvals[i])] = keyvals[i+1]
}
body, err := json.Marshal(buf)
if err != nil {
return err
}
body, _ := json.Marshal(buf)
fmt.Println("ww", string(body))
l.list <- body
return nil
}

@ -0,0 +1,14 @@
package mq
import (
"git.diulo.com/mogfee/protoc-gen-kit/log"
"testing"
)
func Test_nsqLogger_Log(t *testing.T) {
logger := log.With(NewNsqLogger("localhost:4150", "app_log"),
"ts", log.DefaultTimestamp,
"caller", log.DefaultCaller,
)
logger.Log(log.LevelInfo, "user name ttt")
}
Loading…
Cancel
Save