# README
log
import "github.com/brpaz/lib-go/storage/db/log"
Index
- type GormLogger
- func NewGormLogger(logger log.Logger, opts ...GormLoggerOptionFunc) *GormLogger
- func (gl *GormLogger) Error(ctx context.Context, msg string, args ...interface{})
- func (gl *GormLogger) Info(ctx context.Context, msg string, args ...interface{})
- func (gl *GormLogger) LogLevel() gorml.LogLevel
- func (gl *GormLogger) LogMode(level logger.LogLevel) logger.Interface
- func (gl *GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)
- func (gl *GormLogger) Warn(ctx context.Context, msg string, args ...interface{})
- type GormLoggerOptionFunc
- type GormLoggerOpts
type GormLogger
GormLogger is a logger adapter between the application's Logger and GORM's logger interface.
type GormLogger struct {
// contains filtered or unexported fields
}
func NewGormLogger
func NewGormLogger(logger log.Logger, opts ...GormLoggerOptionFunc) *GormLogger
NewGormLogger creates a new GormLogger instance with the provided options.
func (*GormLogger) Error
func (gl *GormLogger) Error(ctx context.Context, msg string, args ...interface{})
Error logs error messages if the log level permits it.
func (*GormLogger) Info
func (gl *GormLogger) Info(ctx context.Context, msg string, args ...interface{})
Info logs informational messages if the log level permits it.
func (*GormLogger) LogLevel
func (gl *GormLogger) LogLevel() gorml.LogLevel
LogLevel returns the current logging level.
func (*GormLogger) LogMode
func (gl *GormLogger) LogMode(level logger.LogLevel) logger.Interface
LogMode sets the logging level for a specific instance of GormLogger.
func (*GormLogger) Trace
func (gl *GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)
Trace logs SQL query details, including execution time, errors, and affected rows.
func (*GormLogger) Warn
func (gl *GormLogger) Warn(ctx context.Context, msg string, args ...interface{})
Warn logs warning messages if the log level permits it.
type GormLoggerOptionFunc
GormLoggerOptionFunc is a function that modifies GormLoggerOpts.
type GormLoggerOptionFunc func(*GormLoggerOpts)
func WithIgnoreRecordNotFoundError
func WithIgnoreRecordNotFoundError(ignore bool) GormLoggerOptionFunc
WithIgnoreRecordNotFoundError sets whether to ignore RecordNotFoundError errors.
func WithSilent
func WithSilent(silent bool) GormLoggerOptionFunc
WithSilent sets whether the logger should be silent.
func WithSlowThreshold
func WithSlowThreshold(threshold time.Duration) GormLoggerOptionFunc
WithSlowThreshold sets the slow threshold for SQL queries.
type GormLoggerOpts
GormLoggerOpts contains the options for configuring a GormLogger.
type GormLoggerOpts struct {
SlowThreshold time.Duration
IgnoreRecordNotFoundError bool
Logger log.Logger
Silent bool
}
Generated by gomarkdoc