prettylogzap

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2021 License: MIT Imports: 9 Imported by: 0

README

Pretty Log Zap

Formata a exibição de logs estruturados em JSON em um formato compatível com seres humanos.

Prettylog

Utilização

import (
	"fmt"

	"github.com/globocom/prettylogzap"
	"go.uber.org/zap"
)


func NewLoggerDevelopment() (*zap.Logger, error) {

	// create zap config
	zapConf = zap.NewDevelopmentConfig()
	zapConf.DisableCaller = true

	// set encoding json
	zapConf.Encoding = "json"

	// set output path:
	// pretty://stderr
	// pretty://stdout
	zapConf.OutputPaths = []string{"pretty://stdout"}

	// register pretty sink
	prettySink := prettylogzap.NewPrettySink(zapConf.EncoderConfig)
	if err := zap.RegisterSink("pretty", prettySink); err != nil {
		return nil, fmt.Errorf("register prettysink error: %w", err)
	}

	logger, err := zapConf.Build()
	if err != nil {
		return nil, fmt.Errorf("fail on define zap as logger: %w", err)
	}

	return logger, nil
}

Agradecimento

Esse projeto foi inspirado no projeto prettylog. Obrigado!

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNonParseableLine = errors.New("line could not be parsed")
	ErrInvalidColor     = errors.New("invalid color")
	ErrInvalidName      = errors.New("invalid name")
	ErrOutputPath       = errors.New("invalid output path")
)

Functions

func NewPrettySink

func NewPrettySink(encoderConfig zapcore.EncoderConfig) func(u *url.URL) (zap.Sink, error)

func SetColorPadding

func SetColorPadding(name string, c *color.Color, padding int) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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