Documentation ¶
Index ¶
- type Logger
- func (l *Logger) Error(ctx context.Context, msg string, data ...interface{})
- func (l *Logger) Info(ctx context.Context, msg string, data ...interface{})
- func (l *Logger) LogMode(logger.LogLevel) logger.Interface
- func (l *Logger) Trace(ctx context.Context, begin time.Time, ...)
- func (l *Logger) Warn(ctx context.Context, msg string, data ...interface{})
- type LoggerOption
- type LoggerOptionFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a logging adapter between Gorm an go-logger, do not create this directly, use NewLogger()
func NewLogger ¶
func NewLogger(opts ...LoggerOption) (*Logger, error)
NewLogger creates a new Gorm logger that passes message to go-logger
To inject the logger into Gorm use
package main import ( gormLogger "github.com/coopnorge/go-logger/adapter/gorm" "gorm.io/driver/postgres" "gorm.io/gorm" ) func main() { l, err := gormLogger.NewLogger(gormLogger.WithGlobalLogger()) if err != nil { panic(err) } db, err := gorm.Open(sqlite.Open("test.db"), &gorm.Config{ Logger: l, }) if err != nil { panic(err) } }
func (*Logger) LogMode ¶
LogMode sets the log level, this is ignored and filtering of logs is left to go-logger
type LoggerOption ¶
type LoggerOption interface {
Apply(l *Logger)
}
LoggerOption defines an applicator interface
func WithGlobalLogger ¶
func WithGlobalLogger() LoggerOption
WithGlobalLogger configures Grom to use our global logger
func WithLogger ¶
func WithLogger(logger *coopLogger.Logger) LoggerOption
WithLogger configures Grom to use a logger instance
func WithSQLTrace ¶ added in v0.10.0
func WithSQLTrace() LoggerOption
WithSQLTrace configures Gorm to output SQL trace logs
type LoggerOptionFunc ¶
type LoggerOptionFunc func(l *Logger) //nolint:all
LoggerOptionFunc defines a function which modifies a logger
func (LoggerOptionFunc) Apply ¶
func (lof LoggerOptionFunc) Apply(l *Logger)
Apply redirects a function call to the function receiver
Click to show internal directories.
Click to hide internal directories.