Your Question
Is there a way to only log certain queries? In particular, I only want the logger to log statements that modify the DB (e.g. CREATE, UPDATE, DELETE) statements, but not SELECT statements.
Expected answer
One proposal would be to add a predicate function to logger.Config that returns true if the statement should be logged, e.g.:
newLogger := logger.New(
log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer
logger.Config{
Decider: func(expr *clause.Expr) bool {
return strings.Contains(expr.SQL, "UPDATE")
},
},
)
clause.Expr is just an example, there might be some better data structure to pass to the predicate.
Comment From: a631807682
https://gorm.io/docs/logger.html#Customize-Logger
You can achieve this by overriding Trace.