gormslog

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: MIT Imports: 9 Imported by: 1

README

gorm-slog

Go Report Card PkgGoDev

Logger for gorm based on log/slog.

package main

import (
    "gorm.io/gorm"
    "gorm.io/driver/sqlite"
    "github.com/onrik/gorm-slog"
)

func main() {
    db, err := gorm.Open(sqlite.Open("db.sqlite"), &gorm.Config{
        Logger: gormslog.New(nil),
    })
    if err != nil {
        panic("failed to connect database")
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger struct {
	SlowThreshold         time.Duration
	SkipErrRecordNotFound bool
	SkipErrContexCanceled bool
	Debug                 bool
	MsgFormatter          func(sql string, elapsed time.Duration, source string) string
	// contains filtered or unexported fields
}

func New

func New(logger Slog) *Logger

func (*Logger) Error

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

func (*Logger) Info

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

func (*Logger) LogMode

func (*Logger) Trace

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

func (*Logger) Warn

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

type Slog added in v1.1.1

type Slog interface {
	DebugContext(ctx context.Context, msg string, args ...any)
	InfoContext(ctx context.Context, msg string, args ...any)
	WarnContext(ctx context.Context, msg string, args ...any)
	ErrorContext(ctx context.Context, msg string, args ...any)
}

Jump to

Keyboard shortcuts

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