internal

package
v0.0.0-...-aac4589 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package internal of logger unifies different types of loggers into interfaces Logger. For example it allows to upgrade simple fmt.Printf to be a fully functional Logger. Therefore multiple wrappers are implemented here to provide different functions which could be missing in some loggers.

Package internal of logger unifies different types of loggers into interfaces Logger. For example it allows to upgrade simple fmt.Printf to be a fully functional Logger. Therefore multiple wrappers are implemented here to provide different functions which could be missing in some loggers.

Package internal of logger unifies different types of loggers into interfaces Logger. For example it allows to upgrade simple fmt.Printf to be a fully functional Logger. Therefore multiple wrappers are implemented here to provide different functions which could be missing in some loggers.

Package internal of logger unifies different types of loggers into interfaces Logger. For example it allows to upgrade simple fmt.Printf to be a fully functional Logger. Therefore multiple wrappers are implemented here to provide different functions which could be missing in some loggers.

Package internal of logger unifies different types of loggers into interfaces Logger. For example it allows to upgrade simple fmt.Printf to be a fully functional Logger. Therefore multiple wrappers are implemented here to provide different functions which could be missing in some loggers.

Package internal of logger unifies different types of loggers into interfaces Logger. For example it allows to upgrade simple fmt.Printf to be a fully functional Logger. Therefore multiple wrappers are implemented here to provide different functions which could be missing in some loggers.

Package internal of logger unifies different types of loggers into interfaces Logger. For example it allows to upgrade simple fmt.Printf to be a fully functional Logger. Therefore multiple wrappers are implemented here to provide different functions which could be missing in some loggers.

Package internal of logger unifies different types of loggers into interfaces Logger. For example it allows to upgrade simple fmt.Printf to be a fully functional Logger. Therefore multiple wrappers are implemented here to provide different functions which could be missing in some loggers.

Index

Constants

View Source
const (
	// LevelUndefined is the erroneous value of log-level which corresponds
	// to zero-value.
	LevelUndefined = Level(iota)

	// LevelFatal will report about Fatalf-s only.
	LevelFatal

	// LevelPanic will report about Panicf-s and Fatalf-s only.
	LevelPanic

	// LevelError will report about Errorf-s, Panicf-s, ...
	LevelError

	// LevelWarning will report about Warningf-s, Errorf-s, ...
	LevelWarning

	// LevelInfo will report about Infof-s, Warningf-s, ...
	LevelInfo

	// LevelDebug will report about Debugf-s, Infof-s, ...
	LevelDebug
)

Variables

This section is empty.

Functions

func MinimalLoggerLogf

func MinimalLoggerLogf(
	l MinimalLogger,
	level Level,
	format string,
	args ...interface{},
)

MinimalLoggerLogf is an implementation of method Logf (of interface MinimalLoggerCompact) based on MinimalLogger.

This function is implemented here to deduplicate code among logadapter-s.

Types

type DummyLogger

type DummyLogger struct{}

DummyLogger is just a logger which does nothing. To do not duplicate anything we just implement MinimalLoggerCompact and the rest methods could be added using wrappers (see logger.ConvertLogger).

func (DummyLogger) Logf

func (DummyLogger) Logf(_ Level, _ string, _ ...interface{})

Logf implements MinimalLoggerCompact.

type ExtendWrapper

type ExtendWrapper struct {
	MinimalLogger
	Prefix   string
	CurLevel Level
}

ExtendWrapper implements Logger based on MinimalLogger.

Thus if you have only a MinimalLogger, you can extend it to a Logger using this wrapper.

It is called ExtendWrapper because it actually implements only LoggerExtensions.

func (ExtendWrapper) Debugf

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

Debugf implements MinimalLogger.

It calls the backend ExtendWrapper.MinimalLogger.Debugf but also checks if the logging level is satisfied.

func (ExtendWrapper) Errorf

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

Errorf implements MinimalLogger.

It calls the backend ExtendWrapper.MinimalLogger.Errorf but also checks if the logging level is satisfied.

func (ExtendWrapper) Fatalf

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

Fatalf implements MinimalLogger.

It calls the backend ExtendWrapper.MinimalLogger.Fatalf but also checks if the logging level is satisfied.

func (ExtendWrapper) Infof

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

Infof implements MinimalLogger.

It calls the backend ExtendWrapper.MinimalLogger.Infof but also checks if the logging level is satisfied.

func (ExtendWrapper) Level

func (l ExtendWrapper) Level() Level

Level implements LoggerExtensions.

func (ExtendWrapper) OriginalLogger

func (l ExtendWrapper) OriginalLogger() interface{}

OriginalLogger implements LoggerExtensions.

func (ExtendWrapper) Panicf

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

Panicf implements MinimalLogger.

It calls the backend ExtendWrapper.MinimalLogger.Panicf but also checks if the logging level is satisfied.

func (ExtendWrapper) Warnf

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

Warnf implements MinimalLogger.

It calls the backend ExtendWrapper.MinimalLogger.Warnf but also checks if the logging level is satisfied.

func (ExtendWrapper) WithField

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

WithField implements LoggerExtensions.

func (ExtendWrapper) WithFields

func (l ExtendWrapper) WithFields(fields Fields) Logger

WithFields implements LoggerExtensions.

func (ExtendWrapper) WithLevel

func (l ExtendWrapper) WithLevel(level Level) Logger

WithLevel implements LoggerExtensions.

type Fields

type Fields = fields.Fields

Fields is a multiple of fields which are attached to logger/tracer messages.

type Level

type Level int

Level is used to define severity of messages to be reported.

func ParseLogLevel

func ParseLogLevel(in string) (Level, error)

ParseLogLevel parses incoming string into a Level and returns LevelUndefined with an error if an unknown logging level was passed.

func (*Level) Set

func (logLevel *Level) Set(value string) error

Set updates the logging level values based on the passed string value. This method just implements flag.Value and pflag.Value.

func (Level) String

func (logLevel Level) String() string

String just implements fmt.Stringer, flag.Value and pflag.Value.

func (*Level) Type

func (logLevel *Level) Type() string

Type just implements pflag.Value.

type Logger

type Logger interface {
	MinimalLogger
	LoggerExtensions
}

Logger is the interface of a logger provided by an extended context.

This is the complete logger with all the required methods/features.

func WrapMinimalLogger

func WrapMinimalLogger(logger MinimalLogger) Logger

WrapMinimalLogger wraps a MinimalLogger to provide a Logger.

func WrapMinimalLoggerCompact

func WrapMinimalLoggerCompact(logger MinimalLoggerCompact) Logger

WrapMinimalLoggerCompact wraps a MinimalLoggerCompact to provide a Logger.

func WrapPrintf

func WrapPrintf(fn func(format string, args ...interface{})) Logger

WrapPrintf wraps a Printf-like function to provide a Logger.

type LoggerCompact

type LoggerCompact interface {
	MinimalLoggerCompact
	LoggerExtensions
}

LoggerCompact is a kind of logger with one method Logf(level, ...) instead of separate methods Debugf(...), Infof(...), Warnf(...) and so on.

type LoggerExtensions

type LoggerExtensions interface {
	// OriginalLogger returns the original logger without wrappers added
	// by this package.
	OriginalLogger() interface{}

	WithLevels
	WithFields
}

LoggerExtensions includes all the features required for a Logger over MinimalLogger.

type MinimalLogger

type MinimalLogger interface {
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Panicf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
}

MinimalLogger is a simple logger, for example logrus.Entry or zap.SugaredLogger could be candidates of an implementation of this interfaces.

Note: logrus.Entry and zap.SugaredLogger supports structured logging and they have With* methods, but the API is different, so we do not require that methods here. We add support of builtin structured logging and logging levels through logadapter-s, see for example logadapter/logrus.Adapter.Convert.

type MinimalLoggerCompact

type MinimalLoggerCompact interface {
	Logf(logLevel Level, format string, args ...interface{})
}

type UncompactLoggerCompact

type UncompactLoggerCompact struct {
	LoggerCompact
}

UncompactLoggerCompact converts LoggerCompact to Logger.

func (UncompactLoggerCompact) Debugf

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

Debugf implements MinimalLogger.

func (UncompactLoggerCompact) Errorf

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

Errorf implements MinimalLogger.

func (UncompactLoggerCompact) Fatalf

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

Fatalf implements MinimalLogger.

func (UncompactLoggerCompact) Infof

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

Infof implements MinimalLogger.

func (UncompactLoggerCompact) OriginalLogger

func (l UncompactLoggerCompact) OriginalLogger() interface{}

OriginalLogger implements LoggerExtensions.

func (UncompactLoggerCompact) Panicf

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

Panicf implements MinimalLogger.

func (UncompactLoggerCompact) Warnf

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

Warnf implements MinimalLogger.

type UncompactMinimalLoggerCompact

type UncompactMinimalLoggerCompact struct {
	MinimalLoggerCompact
}

UncompactMinimalLoggerCompact converts MinimalLoggerCompact to MinimalLogger.

func (UncompactMinimalLoggerCompact) Debugf

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

Debugf implements MinimalLogger.

func (UncompactMinimalLoggerCompact) Errorf

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

Errorf implements MinimalLogger.

func (UncompactMinimalLoggerCompact) Fatalf

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

Fatalf implements MinimalLogger.

func (UncompactMinimalLoggerCompact) Infof

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

Infof implements MinimalLogger.

func (UncompactMinimalLoggerCompact) OriginalLogger

func (l UncompactMinimalLoggerCompact) OriginalLogger() interface{}

OriginalLogger implements LoggerExtensions.

func (UncompactMinimalLoggerCompact) Panicf

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

Panicf implements MinimalLogger.

func (UncompactMinimalLoggerCompact) Warnf

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

Warnf implements MinimalLogger.

type WithFields

type WithFields interface {
	// WithField returns a logger with added field (used for structured logging).
	WithField(key string, value interface{}) Logger

	// WithFields returns a logger with added fields (used for structured logging).
	WithFields(fields Fields) Logger
}

WithFields requires methods of a logger with support of structured logging.

type WithLevels

type WithLevels interface {
	// Level returns the current logging level.
	Level() Level

	// WithLevel returns a logger with logger level set to the passed argument.
	WithLevel(Level) Logger
}

WithLevels requires methods of a logger with support of logging levels.

Jump to

Keyboard shortcuts

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