log

package
v0.67.13 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2024 License: MIT Imports: 9 Imported by: 1

Documentation

Overview

Package log provides a leveled logger with structured logging support.

Index

Constants

View Source
const (
	CurDir              = "."
	CurDirWithSeparator = CurDir + string(os.PathSeparator)
)

Variables

AllLevels exposes all logging levels

Functions

func Debug

func Debug(args ...any)

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

func Debugf

func Debugf(format string, args ...any)

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

func Debugln

func Debugln(args ...any)

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

func Error

func Error(args ...any)

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

func Errorf

func Errorf(format string, args ...any)

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

func Errorln

func Errorln(args ...any)

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

func Info

func Info(args ...any)

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

func Infof

func Infof(format string, args ...any)

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

func Infoln

func Infoln(args ...any)

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

func Print

func Print(args ...any)

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

func Printf

func Printf(args ...any)

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

func Println

func Println(args ...any)

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

func RemoveAllASCISeq added in v0.67.5

func RemoveAllASCISeq(str string) string

RemoveAllASCISeq returns a string with all ASCII color characters removed.

func ResetASCISeq added in v0.67.5

func ResetASCISeq(str string) string

ResetASCISeq returns a string with the ASCI color reset to the default one.

func SetOptions added in v0.67.5

func SetOptions(opts ...Option)

SetOptions sets the options for the standard logger.

func Trace added in v0.56.4

func Trace(args ...any)

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

func Tracef added in v0.56.4

func Tracef(format string, args ...any)

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

func Warn

func Warn(args ...any)

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

func Warnf

func Warnf(format string, args ...any)

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

func Warnln

func Warnln(args ...any)

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

Types

type Fields added in v0.67.5

type Fields map[string]interface{}

Fields is the type used to pass arguments to `WithFields`.

func (Fields) Keys added in v0.67.5

func (fields Fields) Keys(removeKeys ...string) []string

type Level added in v0.67.5

type Level uint32

Level type

const (
	// StderrLevel level. Used to log error messages that we get from OpenTofu/Terraform stderr.
	StderrLevel Level = iota
	// StdoutLevel level. Used to log messages that we get from OpenTofu/Terraform stdout.
	StdoutLevel
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	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
	// TraceLevel level. Designates finer-grained informational events than the Debug.
	TraceLevel
)

These are the different logging levels.

func FromLogrusLevel added in v0.67.5

func FromLogrusLevel(lvl logrus.Level) Level

FromLogrusLevel converts `logrus.Level` to our `Level`.

func ParseLevel added in v0.67.5

func ParseLevel(str string) (Level, error)

ParseLevel takes a string and returns the Level constant.

func (Level) MarshalText added in v0.67.5

func (level Level) MarshalText() ([]byte, error)

MarshalText implements encoding.MarshalText.

func (Level) ShortName added in v0.67.5

func (level Level) ShortName() string

ShortName returns the level name in third characters.

func (Level) String added in v0.67.5

func (level Level) String() string

String implements fmt.Stringer.

func (Level) TinyName added in v0.67.5

func (level Level) TinyName() string

TinyName returns the level name in one character.

func (Level) ToLogrusLevel added in v0.67.5

func (level Level) ToLogrusLevel() logrus.Level

ToLogrusLevel converts our `Level` to `logrus.Level`.

func (*Level) UnmarshalText added in v0.67.5

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

UnmarshalText implements encoding.TextUnmarshaler.

type Levels added in v0.67.5

type Levels []Level

Levels is a slice of `Level` type.

func (Levels) Contains added in v0.67.5

func (levels Levels) Contains(search Level) bool

Contains returns true if the `Levels` list contains the given search `Level`.

func (Levels) Names added in v0.67.5

func (levels Levels) Names() []string

Names returns a list of full level names.

func (Levels) String added in v0.67.5

func (levels Levels) String() string

String implements the `fmt.Stringer` interface.

func (Levels) ToLogrusLevels added in v0.67.5

func (levels Levels) ToLogrusLevels() []logrus.Level

ToLogrusLevels converts our `Levels` to `logrus.Levels`.

type Logger

type Logger interface {
	// Clone creates a new Logger instance with a copy of the fields from the current one.
	Clone() Logger

	// SetOptions sets the given options to the instance.
	SetOptions(opts ...Option)

	// WithOptions clones and sets the given options for the new instance.
	// In other words, it is a combination of two methods, `log.Clone().SetOptions(...)`, but
	// unlike `SetOptions(...)`, it returns the instance, which is convenient for further actions.
	WithOptions(opts ...Option) Logger

	// WithField adds a single field to the Logger and returns partly cloning instance, the `Entry` structure.
	// This way the field is added to the returned instance only.
	WithField(key string, value any) Logger

	// WithFields adds a struct of fields to the Logger. All it does is call `WithField` for each `Field`.
	WithFields(fields Fields) Logger

	// WithError adds an error as single field to the Logger. The error is added to the returned instance only.
	WithError(err error) Logger

	// WithContext adds a context to the Logger. The context is added to the returned instance only.
	WithContext(ctx context.Context) Logger

	// WithTime overrides the time of the Logger. This only affects the returned instance.
	WithTime(t time.Time) Logger

	// Writer returns an io.Writer that writes to the Logger at the info log level.
	Writer() *io.PipeWriter

	// WriterLevel returns an io.Writer that writes to the Logger at the given log level.
	WriterLevel(level Level) *io.PipeWriter

	// Logf logs a message at the level given as parameter on the Logger.
	Logf(level Level, format string, args ...any)

	// Tracef logs a message at level Trace on the Logger.
	Tracef(format string, args ...any)

	// Debugf logs a message at level Debug on the Logger.
	Debugf(format string, args ...any)

	// Infof logs a message at level Info on the Logger.
	Infof(format string, args ...any)

	// Printf logs a message at level Info on the Logger.
	Printf(format string, args ...any)

	// Warnf logs a message at level Warn on the Logger.
	Warnf(format string, args ...any)

	// Errorf logs a message at level Error on the Logger.
	Errorf(format string, args ...any)

	// Log logs a message at the level given as parameter on the Logger.
	Log(level Level, args ...any)

	// Trace logs a message at level Trace on the Logger.
	Trace(args ...any)

	// Debug logs a message at level Debug on the Logger.
	Debug(args ...any)

	// Info logs a message at level Info on the Logger.
	Info(args ...any)

	// Print logs a message at level Info on the Logger.
	Print(args ...any)

	// Warn logs a message at level Warn on the Logger.
	Warn(args ...any)

	// Error logs a message at level Error on the Logger.
	Error(args ...any)

	// Logln logs a message at the level given as parameter on the Logger.
	Logln(level Level, args ...any)

	// Traceln logs a message at level Trace on the Logger.
	Traceln(args ...any)

	// Debugln logs a message at level Debug on the Logger.
	Debugln(args ...any)

	// Infoln logs a message at level Info on the Logger.
	Infoln(args ...any)

	// Println logs a message at level Info on the Logger.
	Println(args ...any)

	// Warnln logs a message at level Warn on the Logger.
	Warnln(args ...any)

	// Errorln logs a message at level Error on the Logger.
	Errorln(args ...any)
}

Logger wraps the logrus package to have full control over implementing the required functionality, such as adding or removing log levels etc. This also provides developers with an easier way to clone and set parameters.

func Default added in v0.67.5

func Default() Logger

Default returns the standard logger used by the package-level output functions. Typically used as the default logger for various packages. It is highly recommended not to use it to avoid conflicts in tests.

func New added in v0.67.5

func New(opts ...Option) Logger

New returns a new Logger instance.

func WithError

func WithError(err error) Logger

WithError adds an error to log entry, using the value defined in ErrorKey as key.

func WithField added in v0.58.7

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

WithField allocates a new entry and adds a field to it.

func WithFields added in v0.67.5

func WithFields(fields Fields) Logger

WithFields adds a struct of fields to the logger. All it does is call `WithField` for each `Field`.

func WithOptions added in v0.67.5

func WithOptions(opts ...Option) Logger

WithOptions returns a new logger with the given options.

type Option added in v0.67.5

type Option func(logger *logger)

Option is a function to set options for logger.

func WithFormatter added in v0.67.5

func WithFormatter(formatter logrus.Formatter) Option

WithFormatter sets the logger formatter.

func WithHooks added in v0.67.5

func WithHooks(hooks ...logrus.Hook) Option

WithHooks adds hooks to the logger hooks.

func WithLevel added in v0.67.5

func WithLevel(level Level) Option

WithLevel sets the logger level.

func WithOutput added in v0.67.5

func WithOutput(output io.Writer) Option

WithOutput sets the logger output.

Directories

Path Synopsis
Package format provides a logrus formatter that formats log entries in a structured way.
Package format provides a logrus formatter that formats log entries in a structured way.
Package hooks provides hooks for the Terragrunt logger.
Package hooks provides hooks for the Terragrunt logger.
Package writer provides a writer that redirects Write requests to configured logger and level.
Package writer provides a writer that redirects Write requests to configured logger and level.

Jump to

Keyboard shortcuts

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