You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
763 B

3 years ago
3 years ago
  1. package internal
  2. import (
  3. "fmt"
  4. "github.com/flipped-aurora/gin-vue-admin/server/global"
  5. "gorm.io/gorm/logger"
  6. )
  7. type writer struct {
  8. logger.Writer
  9. }
  10. // NewWriter writer 构造函数
  11. // Author [SliverHorn](https://github.com/SliverHorn)
  12. func NewWriter(w logger.Writer) *writer {
  13. return &writer{Writer: w}
  14. }
  15. // Printf 格式化打印日志
  16. // Author [SliverHorn](https://github.com/SliverHorn)
  17. func (w *writer) Printf(message string, data ...interface{}) {
  18. var logZap bool
  19. switch global.GVA_CONFIG.System.DbType {
  20. case "mysql":
  21. logZap = global.GVA_CONFIG.Mysql.LogZap
  22. case "pgsql":
  23. logZap = global.GVA_CONFIG.Pgsql.LogZap
  24. }
  25. if logZap {
  26. global.GVA_LOG.Info(fmt.Sprintf(message+"\n", data...))
  27. } else {
  28. w.Writer.Printf(message, data...)
  29. }
  30. }