operation_log.go 951 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package utils
  4. import (
  5. "context"
  6. "encoding/json"
  7. "smart-site-management-gateway/pb"
  8. "smart-site-management-gateway/pb/v1"
  9. "github.com/jaryhe/gopkgs/logger"
  10. "go.uber.org/zap"
  11. "smart-site-management-gateway/consts"
  12. )
  13. func LogWrite(operation string, uid int64, name string, detail string, er error, projectId int64) {
  14. go func() {
  15. rpcReq := &v1.LogAddRequest{
  16. Operation: operation,
  17. Uid: uid,
  18. Result: 1,
  19. Detail: detail,
  20. Username: name,
  21. Type:consts.LogTypeProject,
  22. ProjectId:projectId,
  23. }
  24. if er != nil {
  25. rpcReq.Result = 2
  26. }
  27. _, err := pb.OperationLog.LogAdd(context.Background(), rpcReq)
  28. if err != nil {
  29. s, _ := json.Marshal(rpcReq)
  30. logger.Error("func",
  31. zap.String("call", "LogAdd"),
  32. zap.String("params", string(s)),
  33. zap.String("error", err.Error()))
  34. return
  35. }
  36. }()
  37. }