logger

package
v1.0.25 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: Apache-2.0 Imports: 12 Imported by: 158

Documentation

Overview

Defines global context-aware logger. The default implementation uses logrus. This package registers "logger" config section on init(). The structure of the config section is expected to be un-marshal-able to Config struct.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

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

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

func Debugf

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

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

func Debugln

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

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

func Error

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

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

func Errorf

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

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

func Errorln

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

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

func Fatal

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

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

func Fatalf

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

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

func Fatalln

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

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

func GetLogWriter added in v0.2.8

func GetLogWriter(ctx context.Context) *io.PipeWriter

Returns a standard io.PipeWriter that logs using the same logger configurations in this package.

func Info

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

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

func Infof

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

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

func InfofNoCtx

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

InfofNoCtx logs a formatted message without context.

func Infoln

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

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

func IsLoggable

func IsLoggable(_ context.Context, level Level) bool

Gets a value indicating whether logs at this level will be written to the logger. This is particularly useful to avoid computing log messages unnecessarily.

func Panic

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

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

func Panicf

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

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

func Panicln

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

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

func Print

func Print(ctx context.Context, args ...interface{})

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

func Printf

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

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

func Println

func Println(ctx context.Context, args ...interface{})

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

func SetConfig

func SetConfig(cfg *Config) error

Sets global logger config

func Warn

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

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

func Warnf

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

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

func Warning

func Warning(ctx context.Context, args ...interface{})

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

func Warningf

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

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

func Warningln

func Warningln(ctx context.Context, args ...interface{})

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

func Warnln

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

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

func WithIndent

func WithIndent(ctx context.Context, additionalIndent string) context.Context

Types

type Config

type Config struct {
	// Determines whether to include source code location in logs. This might incurs a performance hit and is only
	// recommended on debug/development builds.
	IncludeSourceCode bool `json:"show-source" pflag:",Includes source code location in logs."`

	// Determines whether the logger should mute all logs (including panics)
	Mute bool `json:"mute" pflag:",Mutes all logs regardless of severity. Intended for benchmarks/tests only."`

	// Determines the minimum log level to log.
	Level Level `json:"level" pflag:",Sets the minimum logging level."`

	Formatter FormatterConfig `json:"formatter" pflag:",Sets logging format."`
}

Global logger config.

func GetConfig added in v0.2.3

func GetConfig() *Config

func (Config) GetPFlagSet

func (cfg Config) GetPFlagSet(prefix string) *pflag.FlagSet

GetPFlagSet will return strongly types pflags for all fields in Config and its nested types. The format of the flags is json-name.json-sub-name... etc.

type FormatterConfig

type FormatterConfig struct {
	Type FormatterType `json:"type" pflag:",Sets logging format type."`
}

type FormatterType

type FormatterType = string
const (
	FormatterJSON FormatterType = "json"
	FormatterText FormatterType = "text"
	FormatterGCP  FormatterType = "gcp"
)

type GcpEntry added in v0.4.7

type GcpEntry struct {
	Data      map[string]interface{} `json:"data,omitempty"`
	Message   string                 `json:"message,omitempty"`
	Severity  GcpSeverity            `json:"severity,omitempty"`
	Timestamp string                 `json:"timestamp,omitempty"`
}

type GcpFormatter added in v0.4.7

type GcpFormatter struct {
}

GcpFormatter Log formatter compatible with GCP stackdriver logging.

func (*GcpFormatter) Format added in v0.4.7

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

type GcpSeverity added in v0.4.7

type GcpSeverity = string
const (
	GcpSeverityDebug    GcpSeverity = "DEBUG"
	GcpSeverityInfo     GcpSeverity = "INFO"
	GcpSeverityWarning  GcpSeverity = "WARNING"
	GcpSeverityError    GcpSeverity = "ERROR"
	GcpSeverityCritical GcpSeverity = "CRITICAL"
	GcpSeverityAlert    GcpSeverity = "ALERT"
)

https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogSeverity

type Level

type Level = int

Level type.

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
)

These are the different logging levels.

type NoopLogger added in v0.2.3

type NoopLogger struct {
}

func (NoopLogger) Debug added in v0.2.3

func (NoopLogger) Debug(args ...interface{})

func (NoopLogger) Debugf added in v0.2.3

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

func (NoopLogger) Debugln added in v0.2.3

func (NoopLogger) Debugln(args ...interface{})

func (NoopLogger) Error added in v0.2.3

func (NoopLogger) Error(args ...interface{})

func (NoopLogger) Errorf added in v0.2.3

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

func (NoopLogger) Errorln added in v0.2.3

func (NoopLogger) Errorln(args ...interface{})

func (NoopLogger) Fatal added in v0.2.3

func (NoopLogger) Fatal(...interface{})

func (NoopLogger) Fatalf added in v0.2.3

func (NoopLogger) Fatalf(string, ...interface{})

func (NoopLogger) Fatalln added in v0.2.3

func (NoopLogger) Fatalln(...interface{})

func (NoopLogger) Info added in v0.2.3

func (NoopLogger) Info(args ...interface{})

func (NoopLogger) Infof added in v0.2.3

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

func (NoopLogger) Infoln added in v0.2.3

func (NoopLogger) Infoln(args ...interface{})

func (NoopLogger) Panic added in v0.2.3

func (NoopLogger) Panic(...interface{})

func (NoopLogger) Panicf added in v0.2.3

func (NoopLogger) Panicf(string, ...interface{})

func (NoopLogger) Panicln added in v0.2.3

func (NoopLogger) Panicln(...interface{})

func (NoopLogger) Print added in v0.2.3

func (NoopLogger) Print(...interface{})

func (NoopLogger) Printf added in v0.2.3

func (NoopLogger) Printf(string, ...interface{})

func (NoopLogger) Println added in v0.2.3

func (NoopLogger) Println(...interface{})

func (NoopLogger) Warn added in v0.2.3

func (NoopLogger) Warn(args ...interface{})

func (NoopLogger) Warnf added in v0.2.3

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

func (NoopLogger) Warning added in v0.2.3

func (NoopLogger) Warning(args ...interface{})

func (NoopLogger) Warningf added in v0.2.3

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

func (NoopLogger) Warningln added in v0.2.3

func (NoopLogger) Warningln(args ...interface{})

func (NoopLogger) Warnln added in v0.2.3

func (NoopLogger) Warnln(args ...interface{})

func (NoopLogger) WithError added in v0.2.3

func (NoopLogger) WithError(err error) *logrus.Entry

func (NoopLogger) WithField added in v0.2.3

func (NoopLogger) WithField(key string, value interface{}) *logrus.Entry

func (NoopLogger) WithFields added in v0.2.3

func (NoopLogger) WithFields(fields logrus.Fields) *logrus.Entry

Jump to

Keyboard shortcuts

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