clog

package module
v0.0.0-...-3dd9459 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 6 Imported by: 0

README

clog

Context logger contains an interface for a logger and some utilities to inject loggers into contexts without tightly coupling with the logger implementation

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithLogger

func ContextWithLogger(ctx context.Context, logger Logger) context.Context

ContextWithLogger creates a new context with the given logger.

func Debug

func Debug(ctx context.Context, values ...interface{})

func Debugf

func Debugf(ctx context.Context, pattern string, args ...interface{})

func Debugln

func Debugln(ctx context.Context, values ...interface{})

func Error

func Error(ctx context.Context, values ...interface{})

func Errorf

func Errorf(ctx context.Context, pattern string, args ...interface{})

func Errorln

func Errorln(ctx context.Context, values ...interface{})

func Fatal

func Fatal(ctx context.Context, values ...interface{})

func Fatalf

func Fatalf(ctx context.Context, pattern string, args ...interface{})

func Fatalln

func Fatalln(ctx context.Context, values ...interface{})

func Info

func Info(ctx context.Context, values ...interface{})

func Infof

func Infof(ctx context.Context, pattern string, args ...interface{})

func Infoln

func Infoln(ctx context.Context, values ...interface{})

func Panic

func Panic(ctx context.Context, values ...interface{})

func Panicf

func Panicf(ctx context.Context, pattern string, args ...interface{})

func Panicln

func Panicln(ctx context.Context, values ...interface{})

func SetDefault

func SetDefault(logger Logger) error

SetDefault sets the default logger. Using this package should be avoided as much as possible.

func Trace

func Trace(ctx context.Context, values ...interface{})

func Tracef

func Tracef(ctx context.Context, pattern string, args ...interface{})

func Traceln

func Traceln(ctx context.Context, values ...interface{})

func Warn

func Warn(ctx context.Context, values ...interface{})

func Warnf

func Warnf(ctx context.Context, pattern string, args ...interface{})

func Warnln

func Warnln(ctx context.Context, values ...interface{})

Types

type Fields

type Fields map[string]interface{}

Fields is a map of keys to values that captures the fields a logger is carrying.

type Level

type Level uint8

Level is the severity level of a log statement.

const (
	// LevelPanic level, highest level of severity. Logs and then calls panic with the
	// message passed to Debug, Info, ...
	LevelPanic Level = iota
	// LevelFatal level. Logs and then calls `logger.Exit(1)`. It will exit even if the
	// logging level is set to Panic.
	LevelFatal
	// LevelError level. Logs. Used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	LevelError
	// LevelWarn level. Non-critical entries that deserve eyes.
	LevelWarn
	// LevelInfo level. General operational entries about what's going on inside the
	// application.
	LevelInfo
	// LevelDebug level. Usually only enabled when debugging. Very verbose logging.
	LevelDebug
	// LevelTrace level. Designates finer-grained informational events than the Debug.
	LevelTrace
)

func ParseLevel

func ParseLevel(level string) (Level, error)

ParseLevel takes a string level and returns the Logrus log level constant.

type Logger

type Logger interface {
	// Trace logs a message at level Trace on the standard logger.
	Trace(...interface{})
	// Traceln logs a message at level Trace on the standard logger.
	Traceln(...interface{})
	// Tracef logs a message at level Trace on the standard logger.
	Tracef(string, ...interface{})

	// Debug logs a message at level Debug on the standard logger.
	Debug(...interface{})
	// Debugln logs a message at level Debug on the standard logger.
	Debugln(...interface{})
	// Debugf logs a message at level Debug on the standard logger.
	Debugf(string, ...interface{})

	// Info logs a message at level Info on the standard logger.
	Info(...interface{})
	// Infoln logs a message at level Info on the standard logger.
	Infoln(...interface{})
	// Infof logs a message at level Info on the standard logger.
	Infof(string, ...interface{})

	// Warn logs a message at level Warn on the standard logger.
	Warn(...interface{})
	// Warnln logs a message at level Warn on the standard logger.
	Warnln(...interface{})
	// Warnf logs a message at level Warn on the standard logger.
	Warnf(string, ...interface{})

	// Error logs a message at level Error on the standard logger.
	Error(...interface{})
	// Errorln logs a message at level Error on the standard logger.
	Errorln(...interface{})
	// Errorf logs a message at level Error on the standard logger.
	Errorf(string, ...interface{})

	// Fatal logs a message at level Fatal on the standard logger and exit immediately.
	Fatal(...interface{})
	// Fatalln logs a message at level Fatal on the standard logger and exit immediately.
	Fatalln(...interface{})
	// Fatalf logs a message at level Fatal on the standard logger and exit immediately.
	Fatalf(string, ...interface{})

	// Panic logs a message at level Panic on the standard logger.
	Panic(...interface{})
	// Panicln logs a message at level Panic on the standard logger.
	Panicln(...interface{})
	// Panicf logs a message at level Panic on the standard logger.
	Panicf(string, ...interface{})

	// SetLevel sets the log level.
	SetLevel(Level)

	// WithField creates a new logger with the given key and value pair added, existing values get overwritten.
	WithField(key string, value interface{}) Logger

	// WithFields creates a new logger with with the given table of keys and values, existing values get overwritten.
	WithFields(Fields) Logger
}

Logger describes ability to log application events.

func Default

func Default() Logger

Default returns the default logger.

func LoggerFromContext

func LoggerFromContext(ctx context.Context) Logger

LoggerFromContext returns active logger for the given ctx or the default logger if none is specified in the context.

func WithField

func WithField(ctx context.Context, key string, value interface{}) Logger

func WithFields

func WithFields(ctx context.Context, fields Fields) Logger

type LogrusWrapper

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

func NewLogrusWrapper

func NewLogrusWrapper(logger *logrus.Logger) LogrusWrapper

func (LogrusWrapper) Debug

func (l LogrusWrapper) Debug(args ...interface{})

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

func (LogrusWrapper) Debugf

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

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

func (LogrusWrapper) Debugln

func (l LogrusWrapper) Debugln(args ...interface{})

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

func (LogrusWrapper) Error

func (l LogrusWrapper) Error(args ...interface{})

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

func (LogrusWrapper) Errorf

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

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

func (LogrusWrapper) Errorln

func (l LogrusWrapper) Errorln(args ...interface{})

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

func (LogrusWrapper) Fatal

func (l LogrusWrapper) Fatal(args ...interface{})

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

func (LogrusWrapper) Fatalf

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

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

func (LogrusWrapper) Fatalln

func (l LogrusWrapper) Fatalln(args ...interface{})

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

func (LogrusWrapper) Info

func (l LogrusWrapper) Info(args ...interface{})

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

func (LogrusWrapper) Infof

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

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

func (LogrusWrapper) Infoln

func (l LogrusWrapper) Infoln(args ...interface{})

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

func (LogrusWrapper) Panic

func (l LogrusWrapper) Panic(args ...interface{})

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

func (LogrusWrapper) Panicf

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

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

func (LogrusWrapper) Panicln

func (l LogrusWrapper) Panicln(args ...interface{})

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

func (LogrusWrapper) SetFormatter

func (l LogrusWrapper) SetFormatter(formatter logrus.Formatter)

SetFormatter sets a custom logrus formatter.

func (LogrusWrapper) SetLevel

func (l LogrusWrapper) SetLevel(level Level)

SetLevel sets the logger level.

func (LogrusWrapper) Trace

func (l LogrusWrapper) Trace(args ...interface{})

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

func (LogrusWrapper) Tracef

func (l LogrusWrapper) Tracef(format string, args ...interface{})

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

func (LogrusWrapper) Traceln

func (l LogrusWrapper) Traceln(args ...interface{})

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

func (LogrusWrapper) Warn

func (l LogrusWrapper) Warn(args ...interface{})

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

func (LogrusWrapper) Warnf

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

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

func (LogrusWrapper) Warnln

func (l LogrusWrapper) Warnln(args ...interface{})

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

func (LogrusWrapper) WithField

func (l LogrusWrapper) WithField(key string, value interface{}) Logger

WithField adds field to the logger.

func (LogrusWrapper) WithFields

func (l LogrusWrapper) WithFields(fields Fields) Logger

WithFields adds fields to the logger.

Jump to

Keyboard shortcuts

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