sloggorm

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 7 Imported by: 0

README

sloggorm

Intro

slog logging driver for gorm2

Usage

import (
  sloggorm "github.com/chg1f/sloggorm"
  "gorm.io/gorm"
)

func main() {
	tx, _ := gorm.Open(nil, &gorm.Config{Logger: sloggorm.NewLogger(slog.Default(), sloggorm.NewConfig())})
}

Documentation

Overview

Example
tx, _ := gorm.Open(nil, &gorm.Config{Logger: NewLogger(slog.Default(), NewConfig())})
// do something with tx
_ = tx
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	SlowThreshold             time.Duration
	IgnoreRecordNotFoundError bool
	ParameterizedQueries      bool
	LogLevel                  gormlogger.LogLevel
}

func NewConfig

func NewConfig() *Config

type Logger

type Logger struct {
	Config
	*slog.Logger
}

func NewLogger

func NewLogger(logger *slog.Logger, conf *Config) *Logger

func (*Logger) Error

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

func (*Logger) Info

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

func (*Logger) LogMode

func (l *Logger) LogMode(level gormlogger.LogLevel) gormlogger.Interface

func (*Logger) ParamsFilter

func (l *Logger) ParamsFilter(ctx context.Context, sql string, params ...interface{}) (string, []interface{})

func (*Logger) Trace

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

func (*Logger) Warn

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

Jump to

Keyboard shortcuts

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