gormzap

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2023 License: MIT Imports: 7 Imported by: 0

README

Zap logging driver for Gorm

Custom GORM logger implementation enhanced with Zap for improved log management

Install

go get github.com/opslead/gormzap

Usage

zapLogger := zap.Must(zap.NewDevelopment())

logger := gormzap.NewGormZapLogger(gormzap.GormZapLoggerConfig{
    Logger:                    zapLogger,
    LogLevel:                  logger.Info,
    SlowThreshold:             1000 * time.Millisecond,
    IgnoreRecordNotFoundError: false,
})

db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{
    Logger: logger,
})

Contributing

We'd love for you to contribute to this project. You can request new features by creating an issue, or submit a pull request with your contribution.

Issues

If you encountered a problem running this project, you can file an issue

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGormZapLogger

func NewGormZapLogger(config GormZapLoggerConfig) logger.Interface

Types

type GormZapLogger

type GormZapLogger struct {
	// contains filtered or unexported fields
}

func (GormZapLogger) Error

func (gormLogger GormZapLogger) Error(ctx context.Context, str string, args ...interface{})

func (GormZapLogger) Info

func (gormLogger GormZapLogger) Info(ctx context.Context, str string, args ...interface{})

func (GormZapLogger) LogMode

func (gormLogger GormZapLogger) LogMode(logLevel logger.LogLevel) logger.Interface

func (GormZapLogger) Trace

func (gormLogger GormZapLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)

func (GormZapLogger) Warn

func (gormLogger GormZapLogger) Warn(ctx context.Context, str string, args ...interface{})

type GormZapLoggerConfig

type GormZapLoggerConfig struct {
	Logger                    *zap.Logger
	LogLevel                  logger.LogLevel
	SlowThreshold             time.Duration
	IgnoreRecordNotFoundError bool
}

Jump to

Keyboard shortcuts

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