zapgormv2

package module
v0.0.0-...-7655f42 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2021 License: MIT Imports: 6 Imported by: 0

README

zapgormv2

License CI Go Report Card

Guide

Installation

$ go get -u github.com/r-fujiyama/zapgormv2
Example
import (
	"github.com/r-fujiyama/zapgormv2"
	"go.uber.org/zap"
	"gorm.io/gorm"
)

func Example() {
	zapLogger, _ := zap.NewProduction()
	logger := zapgormv2.New(zapLogger)
	logger.SetAsDefault() // optional: configure gorm to use this zapgorm.Logger for callbacks
	db, _ := gorm.Open(nil, &gorm.Config{Logger: logger})

	// do stuff normally
	var _ = db // avoid "unused variable" warn
}

License

MIT

Documentation

Overview

Example
package main

import (
	"github.com/r-fujiyama/zapgormv2"
	"go.uber.org/zap"
	"gorm.io/gorm"
)

func main() {
	zapLogger, _ := zap.NewProduction()
	logger := zapgormv2.New(zapLogger)
	logger.SetAsDefault() // optional: configure gorm to use this zapgorm.Logger for callbacks
	db, _ := gorm.Open(nil, &gorm.Config{Logger: logger})

	// do stuff normally
	var _ = db // avoid "unused variable" warn
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger struct {
	ZapLogger                 *zap.Logger
	LogLevel                  gormlogger.LogLevel
	SlowThreshold             time.Duration
	IgnoreRecordNotFoundError bool
}

Logger that implements gorm.logger.Interface

func New

func New(zapLogger *zap.Logger) Logger

New creates an instance of Logger.

func (Logger) Error

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

Error print error messages.

func (Logger) Info

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

Info print info.

func (Logger) LogMode

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

LogMode log mode.

func (Logger) SetAsDefault

func (l Logger) SetAsDefault()

SetAsDefault set as default logger.

func (Logger) Trace

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

Trace print sql message.

func (Logger) Warn

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

Warn print warn messages.

Jump to

Keyboard shortcuts

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