logging

package
v1.13.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: Apache-2.0 Imports: 15 Imported by: 424

Documentation

Index

Constants

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

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

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

	// DefaultLogLevel is the default log level we want to use for our logrus.Formatter
	DefaultLogLevel logrus.Level = logrus.InfoLevel
)
View Source
const (
	SLevel    = "syslog.level"
	SNetwork  = "syslog.network"
	SAddress  = "syslog.address"
	SSeverity = "syslog.severity"
	SFacility = "syslog.facility"
	STag      = "syslog.tag"
)

Variables

View Source
var DefaultLogger = InitializeDefaultLogger()

DefaultLogger is the base logrus logger. It is different from the logrus default to avoid external dependencies from writing out unexpectedly

Functions

func AddHooks

func AddHooks(hooks ...logrus.Hook)

AddHooks adds additional logrus hook to default logger

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 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 InitializeDefaultLogger

func InitializeDefaultLogger() (logger *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 SetDefaultLogFormat

func SetDefaultLogFormat()

SetDefaultLogFormat updates the DefaultLogger with the DefaultLogFormat

func SetDefaultLogLevel

func SetDefaultLogLevel()

SetDefaultLogLevel updates the DefaultLogger with the DefaultLogLevel

func SetLogFormat

func SetLogFormat(logFormat LogFormat)

SetLogFormat updates the DefaultLogger with a new LogFormat

func SetLogLevel

func SetLogLevel(logLevel logrus.Level)

SetLogLevel updates the DefaultLogger with a new logrus.Level

func SetLogLevelToDebug

func SetLogLevelToDebug()

SetLogLevelToDebug updates the DefaultLogger with the logrus.DebugLevel

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, it will return the default format.

func (LogOptions) GetLogLevel

func (o LogOptions) GetLogLevel() (level logrus.Level)

GetLogLevel returns the log level specified in the provided LogOptions. If it is not set in the options, it will return the default level.

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