log.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package service
  2. import (
  3. "time"
  4. mlog "go-common/app/admin/main/apm/model/log"
  5. "go-common/library/log"
  6. context "go-common/library/net/http/blademaster"
  7. "go-common/library/queue/databus/report"
  8. )
  9. // SQLLog log
  10. type SQLLog struct {
  11. SQLType string
  12. Content interface{}
  13. }
  14. // LogAdd add log
  15. func (s *Service) LogAdd(c context.Context, lg *mlog.Log) (err error) {
  16. l := &mlog.Log{
  17. UserName: lg.UserName,
  18. Business: lg.Business,
  19. Info: lg.Info,
  20. }
  21. if err = s.dao.DB.Create(&l).Error; err != nil {
  22. log.Error("s.LogAdd create error(%v)", err)
  23. }
  24. return
  25. }
  26. // SendLog log
  27. func (s *Service) SendLog(c context.Context, username string, uid int64, tp int, oid int64, action string, context interface{}) (err error) {
  28. report.Manager(&report.ManagerInfo{
  29. Uname: username,
  30. UID: uid,
  31. Business: 71,
  32. Type: tp, // 1 add 2 update 3 delete 4 soft delete 5 Transaction 6 kafka
  33. Oid: oid,
  34. Action: action,
  35. Ctime: time.Now(),
  36. // Index: []interface{}{0, 0},
  37. Content: map[string]interface{}{
  38. "content": context,
  39. },
  40. })
  41. return
  42. }