logger

package
v0.0.0-...-bc1f52c Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LevelsMap = map[string]zapcore.Level{
	"EMERGENCY": zapcore.PanicLevel,
	"ALERT":     zapcore.FatalLevel,
	"CRITICAL":  zapcore.FatalLevel,
	"ERROR":     zapcore.ErrorLevel,
	"WARNING":   zapcore.WarnLevel,
	"NOTICE":    zapcore.InfoLevel,
	"INFO":      zapcore.InfoLevel,
	"DEBUG":     zapcore.DebugLevel,
}

LevelsMap is a map to Logrus log levels

Functions

func AddFields

func AddFields(ctx context.Context, fields ...zapcore.Field)

func NewLogger

func NewLogger(GraylogEndpoint string, GraylogLevel, CLILevel Level) (*zap.Logger, error)

NewLogger instanciate a new zap.Logger that will output to both console and graylog. If GraylogEndpoint == "", no data will be send to graylog.

func ToContext

func ToContext(ctx context.Context, logger *zap.Logger) context.Context

func WithContext

func WithContext(ctx context.Context) *zap.Logger

Types

type GELFEncoder

type GELFEncoder struct {
	zapcore.Encoder
}

GELFEncoder is a gelf encoder. It will use an underlying json encoder to encode entries to the gelf format. See http://docs.graylog.org/en/2.4/pages/gelf.html.

func NewGELFEncoder

func NewGELFEncoder() *GELFEncoder

NewGELFEncoder instanciate a new GELFEncoder.

func (GELFEncoder) Clone

func (e GELFEncoder) Clone() zapcore.Encoder

Clone implements the encoder interface.

func (GELFEncoder) EncodeEntry

func (e GELFEncoder) EncodeEntry(entry zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error)

EncodeEntry escape the keys following the gelf spec, then the underlying encoder will encode the entry.

type GELFWriter

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

GELFWriter is a writter following the GELF specs. It will write in udp using a gzip compression.

func NewGELFWriter

func NewGELFWriter(addr string) (*GELFWriter, error)

NewGELFWriter will create a new GELFWriter. We expect a valid udp address.

func (*GELFWriter) Sync

func (w *GELFWriter) Sync() error

Sync implements WriteSyncer.

func (*GELFWriter) Write

func (w *GELFWriter) Write(buf []byte) (int, error)

Write implements io.Writer.

type Level

type Level zapcore.Level

Level implements the UnmarshalText Interface to be able to be load into the config. It is mainly used for parsing configuration with github.com/kelseyhightower/envconfig.

func (Level) String

func (l Level) String() string

String returns a lower-case ASCII representation of the log level.

func (*Level) UnmarshalText

func (l *Level) UnmarshalText(text []byte) error

UnmarshalText unmarshal a text to a level. Returns an error if no level match.

Jump to

Keyboard shortcuts

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