package
0.0.0-20241221112132-06f9af878c14
Repository: https://github.com/brpaz/lib-go.git
Documentation: pkg.go.dev

# README

log

import "github.com/brpaz/lib-go/storage/db/log"

Index

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