gorm

package
v0.11.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

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) Error

func (l *Logger) Error(ctx context.Context, msg string, data ...interface{})

Error writes error level statements to the log

func (*Logger) Info

func (l *Logger) Info(ctx context.Context, msg string, data ...interface{})

Info writes info level statements to the log

func (*Logger) LogMode

func (l *Logger) LogMode(logger.LogLevel) logger.Interface

LogMode sets the log level, this is ignored and filtering of logs is left to go-logger

func (*Logger) Trace

func (l *Logger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)

Trace write SQL trace to the log

func (*Logger) Warn

func (l *Logger) Warn(ctx context.Context, msg string, data ...interface{})

Warn writes warn level statements to the log

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL