log

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DebugLevel logs are typically voluminous, and are usually disabled in
	// production.
	DebugLevel = Level(zap.DebugLevel)
	// InfoLevel is the default logging priority.
	InfoLevel = Level(zap.InfoLevel)
	// WarnLevel logs are more important than Info, but don't need individual
	// human review.
	WarnLevel = Level(zap.WarnLevel)
	// ErrorLevel logs are high-priority. If an application is running smoothly,
	// it shouldn't generate any error-level logs.
	ErrorLevel = Level(zap.ErrorLevel)
	// DPanicLevel logs are particularly important errors. In development the
	// logger panics after writing the message.
	DPanicLevel = Level(zap.DPanicLevel)
	// PanicLevel logs a message, then panics.
	PanicLevel = Level(zap.PanicLevel)
	// FatalLevel logs a message, then calls os.Exit(1).
	FatalLevel = Level(zap.FatalLevel)
)

Duplicated constants from zap for more intuitive usage

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

Debug calls log.Debug

func Debugf

func Debugf(template string, args ...interface{})

Debugf calls log.Debugf

func Debugw

func Debugw(template string, kv ...interface{})

Debugw calls log.Debugw

func Error

func Error(args ...interface{})

Error calls log.Error

func Errorf

func Errorf(template string, args ...interface{})

Errorf calls log.Errorf and stores the error message into the ErrorFile

func Errorw

func Errorw(template string, kv ...interface{})

Errorw calls log.Errorw

func Fatal

func Fatal(args ...interface{})

Fatal calls log.Fatal

func Fatalf

func Fatalf(template string, args ...interface{})

Fatalf calls log.Warnf

func Fatalw

func Fatalw(template string, kv ...interface{})

Fatalw calls log.Fatalw

func GetRequestIDFromContext

func GetRequestIDFromContext(ctx context.Context) string

GetRequestIDFromContext extracts requestID from context

func Info

func Info(args ...interface{})

Info calls log.Info

func Infof

func Infof(template string, args ...interface{})

Infof calls log.Infof

func Infow

func Infow(template string, kv ...interface{})

Infow calls log.Infow

func NewLogger

func NewLogger(levelStr string, outputs []string) (*zap.Logger, *zap.AtomicLevel, error)

NewLogger creates the logger with defined level. outputs defines the outputs where the logs will be sent. By default, outputs contains "stdout", which prints the logs at the output of the process. To add a log file as output, the path should be added at the outputs array. To avoid printing the logs but storing them on a file, can use []string{"pathtofile.log"}

func Panic

func Panic(args ...interface{})

Panic calls log.Panic

func SetLevel

func SetLevel(level Level)

SetLevel sets level

func SetLevelStr

func SetLevelStr(levelStr string)

SetLevelStr sets level of default logger from level name Valid values: debug, info, warn, error, dpanic, panic, fatal

func Warn

func Warn(args ...interface{})

Warn calls log.Warn

func Warnf

func Warnf(template string, args ...interface{})

Warnf calls log.Warnf

func Warnw

func Warnw(template string, kv ...interface{})

Warnw calls log.Warnw

Types

type ContextLogger

type ContextLogger struct {
	Log     *zap.SugaredLogger
	Context context.Context
}

ContextLogger is logger that will use context for additional fields

func WithContext

func WithContext(ctx context.Context) *ContextLogger

WithContext creates logger with context

func (*ContextLogger) Debug

func (l *ContextLogger) Debug(args ...interface{})

Debug calls log.Debug

func (*ContextLogger) Debugf

func (l *ContextLogger) Debugf(template string, args ...interface{})

Debugf calls log.Debugf with context fields

func (*ContextLogger) Debugw

func (l *ContextLogger) Debugw(msg string, kv ...interface{})

Debugw is zap debug with context

func (*ContextLogger) Error

func (l *ContextLogger) Error(args ...interface{})

Error calls log.Error with context fields

func (*ContextLogger) Errorf

func (l *ContextLogger) Errorf(template string, args ...interface{})

Errorf calls log.Errorf and stores the error message into the ErrorFile

func (*ContextLogger) Errorw

func (l *ContextLogger) Errorw(msg string, kv ...interface{})

Errorw is zap Errorw with context

func (*ContextLogger) Fatal

func (l *ContextLogger) Fatal(args ...interface{})

Fatal calls log.Fatal with context fields

func (*ContextLogger) Fatalf

func (l *ContextLogger) Fatalf(template string, args ...interface{})

Fatalf calls log.Fatalf with context fields

func (*ContextLogger) Info

func (l *ContextLogger) Info(args ...interface{})

Info calls log.Info

func (*ContextLogger) Infof

func (l *ContextLogger) Infof(template string, args ...interface{})

Infof calls log.Infof with context fields

func (*ContextLogger) Infow

func (l *ContextLogger) Infow(msg string, kv ...interface{})

Infow is zap Infow with context

func (*ContextLogger) Panicw

func (l *ContextLogger) Panicw(msg string, kv ...interface{})

Panicw is zap Panicw with context

func (*ContextLogger) Warn

func (l *ContextLogger) Warn(args ...interface{})

Warn calls log.Warn with context fields

func (*ContextLogger) Warnf

func (l *ContextLogger) Warnf(template string, args ...interface{})

Warnf calls log.Warnf with context fields

func (*ContextLogger) Warnw

func (l *ContextLogger) Warnw(msg string, kv ...interface{})

Warnw is zap Warnw with context

type Level

type Level zapcore.Level

Level is log level for any logger

Jump to

Keyboard shortcuts

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