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.

39 lines
951 B

3 years ago
  1. package internal
  2. import (
  3. "log"
  4. "os"
  5. "time"
  6. "autocode/global"
  7. "gorm.io/gorm"
  8. "gorm.io/gorm/logger"
  9. )
  10. var Gorm = new(_gorm)
  11. type _gorm struct{}
  12. // Config gorm 自定义配置
  13. // Author [SliverHorn](https://github.com/SliverHorn)
  14. func (g *_gorm) Config() *gorm.Config {
  15. config := &gorm.Config{DisableForeignKeyConstraintWhenMigrating: true}
  16. _default := logger.New(NewWriter(log.New(os.Stdout, "\r\n", log.LstdFlags)), logger.Config{
  17. SlowThreshold: 200 * time.Millisecond,
  18. LogLevel: logger.Warn,
  19. Colorful: true,
  20. })
  21. switch global.GVA_CONFIG.Mysql.LogMode {
  22. case "silent", "Silent":
  23. config.Logger = _default.LogMode(logger.Silent)
  24. case "error", "Error":
  25. config.Logger = _default.LogMode(logger.Error)
  26. case "warn", "Warn":
  27. config.Logger = _default.LogMode(logger.Warn)
  28. case "info", "Info":
  29. config.Logger = _default.LogMode(logger.Info)
  30. default:
  31. config.Logger = _default.LogMode(logger.Info)
  32. }
  33. return config
  34. }