logging

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 8 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Formatter

type Formatter struct {
	// FieldsOrder - default: fields sorted alphabetically
	FieldsOrder []string

	// TimestampFormat - default: time.StampMilli = "Jan _2 15:04:05.000"
	TimestampFormat string

	// HideKeys - show [fieldValue] instead of [fieldKey:fieldValue]
	HideKeys bool

	// NoColors - disable colors
	NoColors bool

	// NoFieldsColors - apply colors only to the level, default is level + fields
	NoFieldsColors bool

	// NoFieldsSpace - no space between fields
	NoFieldsSpace bool

	// ShowFullLevel - show a full level [WARNING] instead of [WARN]
	ShowFullLevel bool

	// NoUppercaseLevel - no upper case for level value
	NoUppercaseLevel bool

	// WithFields bool - show fields
	WithFields bool

	// TrimMessages - trim whitespaces on messages
	TrimMessages bool

	// CallerFirst - print caller info first
	CallerFirst bool

	// CustomCallerFormatter - set custom formatter for caller info
	CustomCallerFormatter func(*logrus.Entry) string
}

Formatter - logrus formatter, implements logrus.Formatter

func (*Formatter) Format

func (f *Formatter) Format(entry *logrus.Entry) ([]byte, error)

Format an log entry

type Logger

type Logger interface {
	// Trace logs a message at level Trace on the standard logger.
	Trace(args ...interface{})
	// Debug logs a message at level Debug on the standard logger.
	Debug(args ...interface{})
	// Print logs a message at level Info on the standard logger.
	Print(args ...interface{})
	// Info logs a message at level Info on the standard logger.
	Info(args ...interface{})
	// Warn logs a message at level Warn on the standard logger.
	Warn(args ...interface{})
	// Warning logs a message at level Warn on the standard logger.
	Warning(args ...interface{})
	// Error logs a message at level Error on the standard logger.
	Error(args ...interface{})
	// Panic logs a message at level Panic on the standard logger.
	Panic(args ...interface{})
	// Fatal logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
	Fatal(args ...interface{})
	// Tracef logs a message at level Trace on the standard logger.
	Tracef(format string, args ...interface{})
	// Debugf logs a message at level Debug on the standard logger.
	Debugf(format string, args ...interface{})
	// Printf logs a message at level Info on the standard logger.
	Printf(format string, args ...interface{})
	// Infof logs a message at level Info on the standard logger.
	Infof(format string, args ...interface{})
	// Warnf logs a message at level Warn on the standard logger.
	Warnf(format string, args ...interface{})
	// Warningf logs a message at level Warn on the standard logger.
	Warningf(format string, args ...interface{})
	// Errorf logs a message at level Error on the standard logger.
	Errorf(format string, args ...interface{})
	// Panicf logs a message at level Panic on the standard logger.
	Panicf(format string, args ...interface{})
	// Fatalf logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
	Fatalf(format string, args ...interface{})
	// Traceln logs a message at level Trace on the standard logger.
	Traceln(args ...interface{})
	// Debugln logs a message at level Debug on the standard logger.
	Debugln(args ...interface{})
	// Println logs a message at level Info on the standard logger.
	Println(args ...interface{})
	// Infoln logs a message at level Info on the standard logger.
	Infoln(args ...interface{})
	// Warnln logs a message at level Warn on the standard logger.
	Warnln(args ...interface{})
	// Warningln logs a message at level Warn on the standard logger.
	Warningln(args ...interface{})
	// Errorln logs a message at level Error on the standard logger.
	Errorln(args ...interface{})
	// Panicln logs a message at level Panic on the standard logger.
	Panicln(args ...interface{})
	// Fatalln logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
	Fatalln(args ...interface{})
}

Logger defines the common logging operations.

func NewLogger

func NewLogger(config LoggerConfiguration) Logger

NewLogger creates a Logger proxy instance.

type LoggerConfiguration

type LoggerConfiguration struct {
	Level        string `envconfig:"LOG_LEVEL" default:"debug"`
	Output       string `envconfig:"LOG_OUTPUT" default:""`
	CallerFirst  bool   `envconfig:"LOG_CALLER_FIRST" default:"false"`
	TrimMessages bool   `envconfig:"LOG_TRIM_MESSAGES" default:"true"`
	HideKeys     bool   `envconfig:"LOG_HIDE_KEYS" default:"false"`
}

LoggerConfiguration defines a struct with required environment variables for logger

func (*LoggerConfiguration) LoadFromEnvVars

func (lc *LoggerConfiguration) LoadFromEnvVars() error

LoadFromEnvVars from the Logger

Jump to

Keyboard shortcuts

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