logger

package
v0.0.0-...-54413df Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: Apache-2.0 Imports: 14 Imported by: 7

Documentation

Index

Constants

View Source
const (
	// Logger encoding types.
	EncodingJSON  = "json"
	EncodingPlain = "plain"

	// LogLevelPanic level, highest level of severity. Logs and then calls panic with the
	// message passed to Debug, Info, ...
	LogLevelPanic = "PANIC"
	// LogLevelFatal level. Logs and then calls `os.Exit(1)`. It will exit even if the
	// logging level is set to Panic.
	LogLevelFatal = "FATAL"
	// LogLevelError level. Logs. Used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	LogLevelError = "ERROR"
	// LogLevelWarn level. Non-critical entries that deserve eyes.
	LogLevelWarn = "WARN"
	// LogInfoLevel level. General operational entries about what's going on inside the
	// application.
	LogLevelInfo = "INFO"
	// LogLevelDebug level. Usually only enabled when debugging. Very verbose logging.
	LogLevelDebug = "DEBUG"
)

Variables

Functions

func Debug

func Debug(args ...interface{})

Debug logs a message at level Debug on the standard logger.

func Debugf

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

Debugf logs a message at level Debug on the standard logger.

func Debugln

func Debugln(args ...interface{})

Debugln logs a message at level Debug on the standard logger.

func Error

func Error(args ...interface{})

Error logs a message at level Error on the standard logger.

func ErrorField

func ErrorField(err error) zap.Field

ErrorField creates a zap.Field for the corresponding error.

By default it creates zapcore.ErrorType field the same way zap.Error() does it.

If the error implements the Location interface from github.com/sumup-oss/go-pkgs/errors, it will add a `trace` field in the log with the error stack trace.

The Location interface looks like this:

  interface {
		Location() (function, file string, line int)
	}

func Errorf

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

Errorf logs a message at level Error on the standard logger.

func Errorln

func Errorln(args ...interface{})

Errorln logs a message at level Error on the standard logger.

func Fatal

func Fatal(args ...interface{})

Fatal logs a message at level Fatal on the standard logger.

func Fatalf

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

Fatalf logs a message at level Fatal on the standard logger.

func Fatalln

func Fatalln(args ...interface{})

Fatalln logs a message at level Fatal on the standard logger.

func HTTPRequestDump

func HTTPRequestDump(key string, req *http.Request) zap.Field

HTTPRequestDump creates a zap.Field that can dump http request lazily.

It is typically used with logger Debug calls. NOTE: The http request body is not dumped. For that use HTTRequestDumpBody.

func HTTPRequestDumpBody

func HTTPRequestDumpBody(key string, req *http.Request) zap.Field

HTTPRequestDumpBody creates a zap.Field that can dump http request along with its body lazily.

It is typically used with logger Debug calls. NOTE: If you want to dump the request path and headers only, use HTTPRequestDump.

func HTTPResponseDump

func HTTPResponseDump(key string, req *http.Response) zap.Field

HTTPResponseDump creates a zap.Field that can dump http response lazily.

It is typically used with logger Debug calls. NOTE: The http response body is not dumped. For that use HTTResponseDumpBody.

func HTTPResponseDumpBody

func HTTPResponseDumpBody(key string, req *http.Response) zap.Field

HTTPResponseDumpBody creates a zap.Field that can dump http request along with its body lazily.

It is typically used with logger Debug calls. NOTE: If you want to dump the response path and headers only, use HTTPResponseDump.

func Info

func Info(args ...interface{})

Info logs a message at level Info on the standard logger.

func Infof

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

Infof logs a message at level Info on the standard logger.

func Infoln

func Infoln(args ...interface{})

Infoln logs a message at level Info on the standard logger.

func Panic

func Panic(args ...interface{})

Panic logs a message at level Panic on the standard logger.

func Panicf

func Panicf(format string, args ...interface{})

Panicf logs a message at level Panic on the standard logger.

func Panicln

func Panicln(args ...interface{})

Panicln logs a message at level Panic on the standard logger.

func Print

func Print(args ...interface{})

Print logs a message at level Info on the standard logger.

func Printf

func Printf(format string, args ...interface{})

Printf logs a message at level Info on the standard logger.

func Println

func Println(args ...interface{})

Println logs a message at level Info on the standard logger.

func SetLevel

func SetLevel(level Level)

func SetLogger

func SetLogger(logger Logger)

func Warn

func Warn(args ...interface{})

Warn logs a message at level Warn on the standard logger.

func Warnf

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

Warnf logs a message at level Warn on the standard logger.

func Warning

func Warning(args ...interface{})

Warning logs a message at level Warn on the standard logger.

func Warningf

func Warningf(format string, args ...interface{})

Warningf logs a message at level Warn on the standard logger.

func Warningln

func Warningln(args ...interface{})

Warningln logs a message at level Warn on the standard logger.

func Warnln

func Warnln(args ...interface{})

Warnln logs a message at level Warn on the standard logger.

Types

type BasicEntry

type BasicEntry struct {
	Time    time.Time
	Level   Level
	Message string
	Buffer  *bytes.Buffer
	Fields  map[string]interface{}
}

func (*BasicEntry) GetBuffer

func (entry *BasicEntry) GetBuffer() *bytes.Buffer

func (*BasicEntry) GetFields

func (entry *BasicEntry) GetFields() map[string]interface{}

func (*BasicEntry) GetLevel

func (entry *BasicEntry) GetLevel() Level

func (*BasicEntry) GetMessage

func (entry *BasicEntry) GetMessage() string

func (*BasicEntry) GetTime

func (entry *BasicEntry) GetTime() time.Time

type Configuration

type Configuration struct {
	Level         string
	Encoding      string
	StdoutEnabled bool
	SyslogEnabled bool
	// SyslogFacility is one of `KERN,USER,MAIL,DAEMON,AUTH,SYSLOG,LPR,NEWS,UUCP,CRON,AUTHPRIV,FTP,LOCAL0,
	// LOCAL1,LOCAL2,LOCAL3,LOCAL4,LOCAL5,LOCAL6,LOCAL7`
	SyslogFacility string
	// SyslogTag is tag for all messages produced
	SyslogTag string
	// Fields is an optional slice of fields which will be logged on each log invokation
	Fields []zapcore.Field
}

type Entry

type Entry interface {
	GetTime() time.Time
	GetLevel() Level
	GetMessage() string
	GetBuffer() *bytes.Buffer
	GetFields() map[string]interface{}
}

type Hook

type Hook interface {
	Levels() []Level
	Fire(Entry) error
}

type Level

type Level uint32
const (
	// PanicLevel level, highest level of severity. Logs and then calls panic with the
	// message passed to Debug, Info, ...
	PanicLevel Level = iota
	// FatalLevel level. Logs and then calls `os.Exit(1)`. It will exit even if the
	// logging level is set to Panic.
	FatalLevel
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	ErrorLevel
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel
	// InfoLevel level. General operational entries about what's going on inside the
	// application.
	InfoLevel
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel
)

func (Level) String

func (level Level) String() string

type Logger

type Logger interface {
	Debug(args ...interface{})
	Print(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{})
	Warning(args ...interface{})
	Error(args ...interface{})
	Panic(args ...interface{})
	Fatal(args ...interface{})
	Debugf(format string, args ...interface{})
	Printf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Warningf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Panicf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
	Debugln(args ...interface{})
	Println(args ...interface{})
	Infoln(args ...interface{})
	Warnln(args ...interface{})
	Warningln(args ...interface{})
	Errorln(args ...interface{})
	Panicln(args ...interface{})
	Fatalln(args ...interface{})
	Logf(level Level, format string, args ...interface{})
	Log(level Level, args ...interface{})
	Logln(level Level, args ...interface{})
	SetLevel(level Level)
	GetLevel() Level
}

func GetLogger

func GetLogger() Logger

type LogrusHook

type LogrusHook struct {
	Hook          Hook
	TriggerLevels []Level
	// contains filtered or unexported fields
}

func (*LogrusHook) Fire

func (hook *LogrusHook) Fire(entry *logrus.Entry) error

func (*LogrusHook) Levels

func (hook *LogrusHook) Levels() []logrus.Level

type LogrusLogger

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

func NewLogrusLogger

func NewLogrusLogger() *LogrusLogger

func (*LogrusLogger) AddHook

func (std *LogrusLogger) AddHook(hook Hook)

AddHook adds a hook to the standard logger hooks.

func (*LogrusLogger) Debug

func (std *LogrusLogger) Debug(args ...interface{})

Debug logs a message at level Debug on the standard logger.

func (*LogrusLogger) Debugf

func (std *LogrusLogger) Debugf(format string, args ...interface{})

Debugf logs a message at level Debug on the standard logger.

func (*LogrusLogger) Debugln

func (std *LogrusLogger) Debugln(args ...interface{})

Debugln logs a message at level Debug on the standard logger.

func (*LogrusLogger) Error

func (std *LogrusLogger) Error(args ...interface{})

Error logs a message at level Error on the standard logger.

func (*LogrusLogger) Errorf

func (std *LogrusLogger) Errorf(format string, args ...interface{})

Errorf logs a message at level Error on the standard logger.

func (*LogrusLogger) Errorln

func (std *LogrusLogger) Errorln(args ...interface{})

Errorln logs a message at level Error on the standard logger.

func (*LogrusLogger) Fatal

func (std *LogrusLogger) Fatal(args ...interface{})

Fatal logs a message at level Fatal on the standard logger.

func (*LogrusLogger) Fatalf

func (std *LogrusLogger) Fatalf(format string, args ...interface{})

Fatalf logs a message at level Fatal on the standard logger.

func (*LogrusLogger) Fatalln

func (std *LogrusLogger) Fatalln(args ...interface{})

Fatalln logs a message at level Fatal on the standard logger.

func (*LogrusLogger) GetLevel

func (std *LogrusLogger) GetLevel() Level

GetLevel returns the standard logger level.

func (*LogrusLogger) Info

func (std *LogrusLogger) Info(args ...interface{})

Info logs a message at level Info on the standard logger.

func (*LogrusLogger) Infof

func (std *LogrusLogger) Infof(format string, args ...interface{})

Infof logs a message at level Info on the standard logger.

func (*LogrusLogger) Infoln

func (std *LogrusLogger) Infoln(args ...interface{})

Infoln logs a message at level Info on the standard logger.

func (*LogrusLogger) Log

func (std *LogrusLogger) Log(level Level, args ...interface{})

Log logs a message at specified level on the standard logger.

func (*LogrusLogger) Logf

func (std *LogrusLogger) Logf(level Level, format string, args ...interface{})

Logf logs a message at specified level on the standard logger.

func (*LogrusLogger) Logln

func (std *LogrusLogger) Logln(level Level, args ...interface{})

Logln logs a message at specified level on the standard logger.

func (*LogrusLogger) Panic

func (std *LogrusLogger) Panic(args ...interface{})

Panic logs a message at level Panic on the standard logger.

func (*LogrusLogger) Panicf

func (std *LogrusLogger) Panicf(format string, args ...interface{})

Panicf logs a message at level Panic on the standard logger.

func (*LogrusLogger) Panicln

func (std *LogrusLogger) Panicln(args ...interface{})

Panicln logs a message at level Panic on the standard logger.

func (*LogrusLogger) Print

func (std *LogrusLogger) Print(args ...interface{})

Print logs a message at level Info on the standard logger.

func (*LogrusLogger) Printf

func (std *LogrusLogger) Printf(format string, args ...interface{})

Printf logs a message at level Info on the standard logger.

func (*LogrusLogger) Println

func (std *LogrusLogger) Println(args ...interface{})

Println logs a message at level Info on the standard logger.

func (*LogrusLogger) SetLevel

func (std *LogrusLogger) SetLevel(level Level)

SetLevel sets the standard logger level.

func (*LogrusLogger) SetOutput

func (std *LogrusLogger) SetOutput(out io.Writer)

SetOutput sets the standard logger output.

func (*LogrusLogger) Warn

func (std *LogrusLogger) Warn(args ...interface{})

Warn logs a message at level Warn on the standard logger.

func (*LogrusLogger) Warnf

func (std *LogrusLogger) Warnf(format string, args ...interface{})

Warnf logs a message at level Warn on the standard logger.

func (*LogrusLogger) Warning

func (std *LogrusLogger) Warning(args ...interface{})

Warning logs a message at level Warn on the standard logger.

func (*LogrusLogger) Warningf

func (std *LogrusLogger) Warningf(format string, args ...interface{})

Warningf logs a message at level Warn on the standard logger.

func (*LogrusLogger) Warningln

func (std *LogrusLogger) Warningln(args ...interface{})

Warningln logs a message at level Warn on the standard logger.

func (*LogrusLogger) Warnln

func (std *LogrusLogger) Warnln(args ...interface{})

Warnln logs a message at level Warn on the standard logger.

type StructuredLogger

type StructuredLogger interface {
	Panic(msg string, fields ...zap.Field)
	Fatal(msg string, fields ...zap.Field)
	Error(msg string, fields ...zap.Field)
	Info(msg string, fields ...zap.Field)
	Warn(msg string, fields ...zap.Field)
	Debug(msg string, fields ...zap.Field)

	// With creates a child logger and adds structured context to it. Fields added
	// to the child don't affect the parent, and vice versa.
	With(fields ...zap.Field) StructuredLogger

	GetLevel() zapcore.Level
	Sync() error
}

type StructuredNopLogger

type StructuredNopLogger struct {
	*zap.Logger
	// contains filtered or unexported fields
}

StructuredNopLogger is no-op StructuredLogger.

func NewStructuredNopLogger

func NewStructuredNopLogger(level string) *StructuredNopLogger

NewStructuredNopLogger returns a no-op StructuredLogger.

Note that if the passed level is not recognized it will default to INFO.

func (*StructuredNopLogger) GetLevel

func (z *StructuredNopLogger) GetLevel() zapcore.Level

func (*StructuredNopLogger) With

func (z *StructuredNopLogger) With(fields ...zap.Field) StructuredLogger

With creates a child logger and adds structured context to it. Fields added to the child don't affect the parent, and vice versa.

type ZapLogger

type ZapLogger struct {
	*zap.Logger
	// contains filtered or unexported fields
}

func NewZapLogger

func NewZapLogger(config Configuration) (*ZapLogger, error)

func (*ZapLogger) GetLevel

func (z *ZapLogger) GetLevel() zapcore.Level

func (*ZapLogger) With

func (z *ZapLogger) With(fields ...zap.Field) StructuredLogger

With creates a child logger and adds structured context to it. Fields added to the child don't affect the parent, and vice versa.

type ZapSyslogCore

type ZapSyslogCore struct {
	zapcore.LevelEnabler
	// contains filtered or unexported fields
}

func NewZapSyslogCore

func NewZapSyslogCore(enab zapcore.LevelEnabler, encoder zapcore.Encoder, writer gsyslog.Syslogger) *ZapSyslogCore

func (*ZapSyslogCore) Check

func (core *ZapSyslogCore) Check(entry zapcore.Entry, checked *zapcore.CheckedEntry) *zapcore.CheckedEntry

NOTE: We pass `entry` by value to satisfy the interface requirements nolint:gocritic

func (*ZapSyslogCore) Sync

func (core *ZapSyslogCore) Sync() error

func (*ZapSyslogCore) With

func (core *ZapSyslogCore) With(fields []zapcore.Field) zapcore.Core

func (*ZapSyslogCore) Write

func (core *ZapSyslogCore) Write(entry zapcore.Entry, fields []zapcore.Field) error

NOTE: We pass `entry` by value to satisfy the interface requirements nolint:gocritic

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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