gormzerolog

package module
v0.0.0-...-3775746 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2019 License: MIT Imports: 7 Imported by: 0

README

gorm-zerolog

Build Status codecov GoDoc license

Alternative logging with zerolog for GORM ⚡️

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

Example

package main

import (
	"github.com/jinzhu/gorm"
	"github.com/Ahmet-Kaplan/gorm-zerolog"
)

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

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

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

	// ...
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger struct {
	ZRLog *zerolog.Logger
	Level zerolog.Level
	Event *zerolog.Event
}

Logger is an alternative implementation of *gorm.Logger

func New

func New(origin *zerolog.Logger, opts ...LoggerOption) *Logger

New create logger object for *gorm.DB from *zeroLog.Logger By default it logs with debug level.

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

type LoggerOption

type LoggerOption func(*Logger)

LoggerOption is an option for Logger.

func WithLevel

func WithLevel(level zerolog.Level) LoggerOption

WithLevel returns Logger option that sets level for gorm logs. It affects only general logs, e.g. those that contain SQL queries. Errors will be logged with error level independently of this option.

type Record

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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