Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: diy generator logger #1264

Merged
merged 16 commits into from
Feb 20, 2025
17 changes: 15 additions & 2 deletions generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func NewGenerator(cfg Config) *Generator {
Config: cfg,
Data: make(map[string]*genInfo),
models: make(map[string]*generate.QueryStructMeta),

logger: log.Default(),
}
}

Expand Down Expand Up @@ -84,12 +86,23 @@ func (i *genInfo) methodInGenInfo(m *generate.InterfaceMethod) bool {
return false
}

// Logger gen logger interface
type Logger interface {
Println(v ...any)
}

// Generator code generator
type Generator struct {
Config

Data map[string]*genInfo //gen query data
models map[string]*generate.QueryStructMeta //gen model data

logger Logger
}

// SetLogger set gen logger
func (g *Generator) SetLogger(logger Logger) {
g.logger = logger
}

// UseDB set db connection
Expand Down Expand Up @@ -278,7 +291,7 @@ func (g *Generator) Execute() {
func (g *Generator) info(logInfos ...string) {
for _, l := range logInfos {
g.db.Logger.Info(context.Background(), l)
log.Println(l)
g.logger.Println(l)
}
}

Expand Down
Loading