gormzap

package module
v0.0.0-...-66d7ca4 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2020 License: MIT Imports: 6 Imported by: 0

README

gormzap

Build Status codecov GoDoc license

Alternative logging with zap for GORM ⚡️

In comparison to gorm's default logger, gormzap is faster, reflection free, low allocations and no regex compilations.

Example

package main

import (
	"github.com/jinzhu/gorm"
	"github.com/wantedly/gorm-zap"
)

const (
	databaseURL = "postgres://postgres:@localhost/gormzap?sslmode=disable"
)

func main() {
	logger, err = zap.NewProduction()
	if err != nil {
		panic(err)
	}

	db, err := gorm.Open("postgres", databaseURL)
	if err != nil {
		panic(err)
	}
	db.LogMode(true)
	db.SetLogger(gormzap.New(logger))

	// ...
}

Performance

According to our benchmark, gormzap makes DB operations at least 5% faster and reduce object allocations.

Simple insert query
Logger Time Object Allocated
default 187940 ns/op 494 allocs/op
gormzap 185383 ns/op 475 allocs/op
Simple select query
Logger Time Object Allocated
default 169361 ns/op 531 allocs/op
gormzap 151304 ns/op 519 allocs/op
Simple select query with 10 placeholders
Logger Time Object Allocated
default 200632 ns/op 720 allocs/op
gormzap 190732 ns/op 645 allocs/op
Simple select query with 100 placeholders
Logger Time Object Allocated
default 444513 ns/op 1723 allocs/op
gormzap 263098 ns/op 1101 allocs/op

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

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

Logger is an alternative implementation of *gorm.Logger

func New

func New(zap *zap.Logger) *Logger

New create logger object for *gorm.DB from *zap.Logger

func (*Logger) Print

func (l *Logger) Print(values ...interface{})

Print passes arguments to Println

func (*Logger) Println

func (l *Logger) Println(values []interface{})

Println format & print log

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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