logger

package
v2.0.52 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0, Apache-2.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

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

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

type GcpFormatter struct {
}

GcpFormatter Log formatter compatible with GCP stackdriver logging.

func (*GcpFormatter) Format

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

type GcpSeverity

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

type NoopLogger struct {
}

func (NoopLogger) Debug

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

func (NoopLogger) Debugf

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

func (NoopLogger) Debugln

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

func (NoopLogger) Error

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

func (NoopLogger) Errorf

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

func (NoopLogger) Errorln

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

func (NoopLogger) Fatal

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

func (NoopLogger) Fatalf

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

func (NoopLogger) Fatalln

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

func (NoopLogger) Info

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

func (NoopLogger) Infof

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

func (NoopLogger) Infoln

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

func (NoopLogger) Panic

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

func (NoopLogger) Panicf

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

func (NoopLogger) Panicln

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

func (NoopLogger) Print

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

func (NoopLogger) Printf

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

func (NoopLogger) Println

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

func (NoopLogger) Warn

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

func (NoopLogger) Warnf

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

func (NoopLogger) Warning

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

func (NoopLogger) Warningf

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

func (NoopLogger) Warningln

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

func (NoopLogger) Warnln

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

func (NoopLogger) WithError

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

func (NoopLogger) WithField

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

func (NoopLogger) WithFields

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