sugaredgorm

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2023 License: MIT Imports: 7 Imported by: 0

README

Version Go Documentation Go Report Card Go Build Status GolangCI-Lint Status codecov Powered by Rake

Sugared Gorm

Custom GORM logger implementation enhanced with SugarLogger for improved log level management and standardized log outputs.

Features

  • Integrate GORM database logging with the powerful SugarLogger library.
  • Easily manage log levels and control verbosity for debugging.
  • Standardized and customizable log outputs for better readability and analysis.

Installation

Now you can add this package via;

go get -u github.com/erhanakp/sugaredgorm

Install godoc for documentation;

go install golang.org/x/tools/cmd/godoc@latest

Usage:

	zap := zap.NewExample()

	gormLoggerValue := sugaredgorm.New(zap.Sugar(), sugaredgorm.Config{
		SlowThreshold:             200 * time.Millisecond,
		Colorful:                  true,
		IgnoreRecordNotFoundError: true,
		ParameterizedQueries:      true,
	})

	_, err := gorm.Open(postgres.New(postgres.Config{
		DSN: "host=localhost",
	}), &gorm.Config{
		Logger: gormLoggerValue,
	})

Rake Tasks

rake -T

rake bump[revision]     # bump version, default is: patch
rake doc[port]          # run doc server
rake lint               # run golangci-lint
rake publish[revision]  # publish new version of the library, default is: patch
rake test               # run tests

Contributor(s)


Contribute

All PR’s are welcome!

  1. fork (https://github.com/erhanakp/sugaredgorm/fork)
  2. Create your branch (git checkout -b my-feature)
  3. commit yours (git commit -am 'add some functionality')
  4. push your branch (git push origin my-feature)
  5. Than create a new Pull Request!

This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.


License

This project is licensed under MIT

Documentation

Index

Constants

View Source
const (
	Reset       = "\033[0m"
	Red         = "\033[31m"
	Green       = "\033[32m"
	Yellow      = "\033[33m"
	Blue        = "\033[34m"
	Magenta     = "\033[35m"
	Cyan        = "\033[36m"
	White       = "\033[37m"
	BlueBold    = "\033[34;1m"
	MagentaBold = "\033[35;1m"
	RedBold     = "\033[31;1m"
	YellowBold  = "\033[33;1m"
)

Colors for logger.

Variables

View Source
var ErrRecordNotFound = errors.New("record not found")

ErrRecordNotFound record not found error for gorm.

Functions

This section is empty.

Types

type Config

type Config struct {
	SlowThreshold             time.Duration
	Colorful                  bool
	IgnoreRecordNotFoundError bool
	ParameterizedQueries      bool
}

Config logger config for gorm.

type Logger

type Logger interface {
	LogMode(gormlogger.LogLevel) gormlogger.Interface
	Info(context.Context, string, ...interface{})
	Warn(context.Context, string, ...interface{})
	Error(context.Context, string, ...interface{})
	Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)
}

Logger interface for gorm logger.

func New

func New(sugerLogger *zap.SugaredLogger, config Config) Logger

New initialize logger.

Jump to

Keyboard shortcuts

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