gormlogger

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

README

gormlogger

A Logger contribe to gorm. Although gorm provide a logger interface for user, it's not so convenient as expected.

This repository intends to provide a more convenient way to implement gorm logger interface.

Install

go get github.com/lawyzheng/gormlogger

Quick Start

to work with logrus


import (
	"github.com/lawyzheng/gormlogger"
	"github.com/sirupsen/logrus"
	"gorm.io/gorm"
)

func main(){
	// to use logrus.Logger
	db, err := gorm.Open(dialector, &gorm.Config{
		Logger: gormlogger.NewLogger(logrus.New()),
	})
	if err != nil {
		panic(err)
	}

	// or to use logrus.Entry
	db, err := gorm.Open(dialector, &gorm.Config{
		Logger: gormlogger.NewLogger(logrus.NewEntry(logrus.New())),
	})
	if err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ElapsedTimeFunc

type ElapsedTimeFunc func(time.Duration)

type ErrorFunc

type ErrorFunc func(error)

type Logger

type Logger struct {
	Logging
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(log Logging) *Logger

func (*Logger) Error

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

func (*Logger) Info

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

func (*Logger) LogMode

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

func (*Logger) SetElapsedTimeFunc

func (l *Logger) SetElapsedTimeFunc(fn ElapsedTimeFunc) *Logger

func (*Logger) SetErrorFunc

func (l *Logger) SetErrorFunc(fn ErrorFunc) *Logger

func (*Logger) SetSqlRowFunc

func (l *Logger) SetSqlRowFunc(fn SqlRowFunc) *Logger

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, msg string, data ...interface{})

type Logging

type Logging interface {
	Tracef(msg string, data ...interface{})
	Infof(msg string, data ...interface{})
	Warnf(msg string, data ...interface{})
	Errorf(msg string, data ...interface{})
}

type SqlRowFunc

type SqlRowFunc func(string, int64)

Jump to

Keyboard shortcuts

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