Categorygithub.com/CIDgravity/gormv2-logrus-fork
modulepackage
1.3.1
Repository: https://github.com/cidgravity/gormv2-logrus-fork.git
Documentation: pkg.go.dev

# README

gormv2-logrus

Easily connect Gorm V2 and logrus with customizable options

Usage example :

package test

import (
	gormv2logrus "github.com/CIDgravity/gormv2-logrus-fork"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
)

func myFunctionToConnectOnMyDB(e *logrus.Entry) {
	gormLogger := gormv2logrus.NewGormlog(gormv2logrus.WithLogrusEntry(e))
	gormLogger.LogMode(logger.Error)

	gormConfig := &gorm.Config{
		Logger:                 gormLogger,
		CreateBatchSize:        1500,
		SkipDefaultTransaction: true,
	}
	
	db, err := gorm.Open(
		"CONNEXION STRING",
		gormConfig,
	)
}

Or you can use with a logrus.Logger :

gormLogger := gormv2logrus.NewGormlog(gormv2logrus.WithLogrus(e))

You can also add customization options :

	slowThresholdDuration, _ := time.ParseDuration("300ms")

	gormLogger := gormv2logrus.NewGormlog(
		gormv2logrus.WithLogrus(e),
		gormv2logrus.WithGormOptions(
			gormv2logrus.GormOptions{
				SlowThreshold: slowThresholdDuration,
				LogLevel:      logger.Error,
				LogLatency:    true,
			},
		),
	)

Colorful option has been removed, because Logrus can't really handle the color code, especially if the logs are redirected to a file, the characters are not removed automatically

Contibuting

Just feel free to open issues, ask questions, make proposals.

# Functions

NewGormlog create an instance of.
No description provided by the author
No description provided by the author
WithLogrus Option is (not compatible with WithLogrusEntry) is used to set your logrus isntance.
WithLogrusEntry Option (not compatible with WithLogrus) used to specify your logrusEntry instance.

# Structs

BannedKeyword represents a rule for scanning for Keyword in log output.
Gormlog must match gorm logger.Interface to be compatible with gorm.
No description provided by the author

# Interfaces

Option interface is used to configure gormv2_logrus options.