logging

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2021 License: Apache-2.0 Imports: 18 Imported by: 424

Documentation

Index

Constants

View Source
const (
	SLevel    = "syslog.level"
	Syslog    = "syslog"
	LevelOpt  = "level"
	FormatOpt = "format"

	LogFormatText LogFormat = "text"
	LogFormatJSON LogFormat = "json"

	// DefaultLogLevelStr is the string representation of DefaultLogLevel. It
	// is used to allow for injection of the logging level via go's ldflags in
	// unit tests, as only injection with strings via ldflags is allowed.
	DefaultLogLevelStr string = "info"

	// DefaultLogFormat is the string representation of the default logrus.Formatter
	// we want to use (possible values: text or json)
	DefaultLogFormat LogFormat = LogFormatText
)

Variables

View Source
var (
	// DefaultLogger is the base logrus logger. It is different from the logrus
	// default to avoid external dependencies from writing out unexpectedly
	DefaultLogger = InitializeDefaultLogger()

	// LevelStringToLogrusLevel maps string representations of logrus.Level into
	// their corresponding logrus.Level.
	LevelStringToLogrusLevel = map[string]logrus.Level{
		"panic":   logrus.PanicLevel,
		"error":   logrus.ErrorLevel,
		"warning": logrus.WarnLevel,
		"info":    logrus.InfoLevel,
		"debug":   logrus.DebugLevel,
	}
)

Functions

func CanLogAt

func CanLogAt(logger *logrus.Logger, level logrus.Level) bool

CanLogAt returns whether a log message at the given level would be logged by the given logger.

func ConfigureLogLevel added in v1.7.0

func ConfigureLogLevel(debug bool)

ConfigureLogLevel configures the logging level of the global logger. If debugging is not enabled, it will set the logging level based off of the logging options configured at bootstrap. Debug being enabled takes precedence over the configuration in the logging options. It is thread-safe.

func GetFormatter

func GetFormatter(format LogFormat) logrus.Formatter

GetFormatter returns a configured logrus.Formatter with some specific values we want to have

func GetLevel

func GetLevel(logger *logrus.Logger) logrus.Level

GetLevel returns the log level of the given logger.

func GetLogLevelFromConfig added in v1.7.0

func GetLogLevelFromConfig() (logrus.Level, bool)

GetLogLevelFromConfig returns the log level provided via global configuration. If the logging level is invalid, ok will be false.

func InitializeDefaultLogger

func InitializeDefaultLogger() *logrus.Logger

InitializeDefaultLogger returns a logrus Logger with a custom text formatter.

func MultiLine

func MultiLine(logFn func(args ...interface{}), output string)

MultiLine breaks a multi line text into individual log entries and calls the logging function to log each entry

func SetLogLevel

func SetLogLevel(level logrus.Level)

SetLogLevel sets the log level on DefaultLogger. This logger is, by convention, the base logger for package specific ones thus setting the level here impacts the default logging behaviour. This function is thread-safe when logging, reading DefaultLogger.LevelOpt is not protected this way, however.

func SetupLogging

func SetupLogging(loggers []string, logOpts LogOptions, tag string, debug bool) error

SetupLogging sets up each logging service provided in loggers and configures each logger with the provided logOpts.

Types

type Limiter

type Limiter struct {
	// contains filtered or unexported fields
}

Limiter is a wrapper around rate.Limiter that does not panic when the limiter is uninitialized. The wrapping also allows more logging specific functionality to be added later without changing all the call sites.

func NewLimiter

func NewLimiter(interval time.Duration, burst int) Limiter

NewLimiter returns a new Limiter allowing log messages to be emitted on average once every 'interval' and upto 'burst' messages during any 'interval'.

func (Limiter) Allow

func (ll Limiter) Allow() bool

Allow returns true if the log message is allowed under the configured rate limit.

type LogFormat

type LogFormat string

type LogOptions

type LogOptions map[string]string

LogOptions maps configuration key-value pairs related to logging.

func (LogOptions) GetLogFormat

func (o LogOptions) GetLogFormat() LogFormat

GetLogFormat returns the log format specified in the provided LogOptions. If it is not set in the options or is invalid, ok will be false.

func (LogOptions) GetLogLevel

func (o LogOptions) GetLogLevel() (level logrus.Level, ok bool)

GetLogLevel returns the log level specified in the provided LogOptions. If it is not set in the options, ok will be false.

Directories

Path Synopsis
Package logfields defines common logging fields which are used across packages
Package logfields defines common logging fields which are used across packages

Jump to

Keyboard shortcuts

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