Documentation ¶
Index ¶
- Constants
- func FilterLevels(maxLevel log.Level) []log.Level
- func FormatForSyslog(entry *log.Entry) string
- func SafeParseLogLevel(logLevel string) log.Level
- type BackgroundHook
- type BackgroundHookOpt
- type ContextHook
- type Destination
- type Formatter
- type NullWriter
- type QueuedLog
- type RateLimitedLogger
- func (logger *RateLimitedLogger) Debug(args ...interface{})
- func (logger *RateLimitedLogger) Debugf(format string, args ...interface{})
- func (logger *RateLimitedLogger) Debugln(args ...interface{})
- func (logger *RateLimitedLogger) Error(args ...interface{})
- func (logger *RateLimitedLogger) Errorf(format string, args ...interface{})
- func (logger *RateLimitedLogger) Errorln(args ...interface{})
- func (logger *RateLimitedLogger) Force() *RateLimitedLogger
- func (logger *RateLimitedLogger) Info(args ...interface{})
- func (logger *RateLimitedLogger) Infof(format string, args ...interface{})
- func (logger *RateLimitedLogger) Infoln(args ...interface{})
- func (logger *RateLimitedLogger) Print(args ...interface{})
- func (logger *RateLimitedLogger) Printf(format string, args ...interface{})
- func (logger *RateLimitedLogger) Println(args ...interface{})
- func (logger *RateLimitedLogger) Warn(args ...interface{})
- func (logger *RateLimitedLogger) Warnf(format string, args ...interface{})
- func (logger *RateLimitedLogger) Warning(args ...interface{})
- func (logger *RateLimitedLogger) Warningf(format string, args ...interface{})
- func (logger *RateLimitedLogger) Warningln(args ...interface{})
- func (logger *RateLimitedLogger) Warnln(args ...interface{})
- func (logger *RateLimitedLogger) WithError(err error) *RateLimitedLogger
- func (logger *RateLimitedLogger) WithField(key string, value interface{}) *RateLimitedLogger
- func (logger *RateLimitedLogger) WithFields(fields logrus.Fields) *RateLimitedLogger
- type RateLimitedLoggerOpt
Constants ¶
const ( // FieldForceFlush is a field name used to signal to the BackgroundHook that it should flush the log after this // message. It can be used as follows: logrus.WithField(FieldForceFlush, true).Info("...") FieldForceFlush = "__flush__" )
Variables ¶
This section is empty.
Functions ¶
func FilterLevels ¶
FilterLevels returns all the logrus.Level values <= maxLevel.
func FormatForSyslog ¶
FormatForSyslog formats logs in a way tailored for syslog. It avoids logging information that is already included in the syslog metadata such as timestamp and PID. The log level _is_ included because syslog doesn't seem to output it by default and it's very useful.
INFO endpoint_mgr.go 434: Skipping configuration of interface because it is oper down. ifaceName="cali1234"
func SafeParseLogLevel ¶
SafeParseLogLevel parses a string version of a logrus log level, defaulting to logrus.PanicLevel on failure.
Types ¶
type BackgroundHook ¶
type BackgroundHook struct {
// contains filtered or unexported fields
}
BackgroundHook is a logrus Hook that (synchronously) formats each log and sends it to one or more Destinations for writing on a background thread. It supports filtering destinations on individual log levels. We write logs from background threads so that blocking of the output stream doesn't block the mainline code. Up to a point, we queue logs for writing, then we start dropping logs.
func NewBackgroundHook ¶
func NewBackgroundHook( levels []log.Level, syslogLevel log.Level, destinations []*Destination, counter prometheus.Counter, opts ...BackgroundHookOpt, ) *BackgroundHook
func (*BackgroundHook) Levels ¶
func (h *BackgroundHook) Levels() []log.Level
func (*BackgroundHook) Start ¶
func (h *BackgroundHook) Start()
type BackgroundHookOpt ¶
type BackgroundHookOpt func(hook *BackgroundHook)
func WithDebugFileRegexp ¶
func WithDebugFileRegexp(re *regexp.Regexp) BackgroundHookOpt
type ContextHook ¶
type ContextHook struct { }
func (ContextHook) Levels ¶
func (hook ContextHook) Levels() []log.Level
type Destination ¶
type Destination struct { // Level is the minimum level that a log must have to be logged to this destination. Level log.Level // Channel is the channel used to queue logs to the background worker thread. Public for // test purposes. Channel chan QueuedLog // contains filtered or unexported fields }
func NewStreamDestination ¶
func NewStreamDestination( level log.Level, writer io.Writer, c chan QueuedLog, disableLogDropping bool, counter prometheus.Counter, ) *Destination
func NewSyslogDestination ¶
func NewSyslogDestination( level log.Level, writer syslogWriter, c chan QueuedLog, disableLogDropping bool, counter prometheus.Counter, ) *Destination
func (*Destination) Close ¶
func (d *Destination) Close()
Close closes the channel to the background goroutine. This is only safe to call if you know that the destination is no longer in use by any thread; in tests, for example.
func (*Destination) LoopWritingLogs ¶
func (d *Destination) LoopWritingLogs()
LoopWritingLogs is intended to be used as a background go-routine. It processes the logs from the channel.
func (*Destination) Send ¶
func (d *Destination) Send(ql QueuedLog) (ok bool)
Send sends a log to the background thread. It returns true on success or false if the channel is blocked.
type Formatter ¶
type Formatter struct { // If specified, prepends the component to the file name. This is useful for when // multiple components are logging to the same file (e.g., calico/node) for distinguishing // which component sourced the log. Component string }
Formatter is our custom log formatter designed to balance ease of machine processing with human readability. Logs include:
- A sortable millisecond timestamp, for scanning and correlating logs
- The log level, near the beginning of the line, to aid in visual scanning
- The PID of the process to make it easier to spot log discontinuities (If you are looking at two disjoint chunks of log, were they written by the same process? Was there a restart in-between?)
- The file name and line number, as essential context
- The message!
- Log fields appended in sorted order
Example:
2017-01-05 09:17:48.238 [INFO][85386] endpoint_mgr.go 434: Skipping configuration of interface because it is oper down. ifaceName="cali1234"
type NullWriter ¶
type NullWriter struct{}
NullWriter is a dummy writer that always succeeds and does nothing.
type QueuedLog ¶
type RateLimitedLogger ¶
type RateLimitedLogger struct {
// contains filtered or unexported fields
}
func NewRateLimitedLogger ¶
func NewRateLimitedLogger(opts ...RateLimitedLoggerOpt) *RateLimitedLogger
NewRateLimitedLogger returns a RateLimitedLogger which can be used for rate limited logging.
Methods are essentially the same as the logrus logging methods, but there is no Panic or Fatal log since these don't make much sense for rate limited logging.
Log requests are only processed if allowed by the logging level. The first processed log will always be written. Subsequent processed logs will not be written within the configured time interval. Once the time interval has passed the next log will be written. The logs include additional fields specifying the number of skipped logs and the minimum time for the next expected log. The Force() method can be used to ensure the log is written - this resets the time for the next log.
Typical use might be as follows:
logger := NewRateLimitedLogger().WithField("key": "my-key") for { logger.Infof("Checking some stuff: %s", myStuff) complete = doSomeStuff() if complete { break } } // Use force to ensure our final log is printed and it contains the summary info about the number of skipped logs. logger.Force().Info("Finished checking stuff")
The config is an optional parameter. If not specified, default values are used (see RateLimitedLoggerConfig for details about the default values).
func (*RateLimitedLogger) Debug ¶
func (logger *RateLimitedLogger) Debug(args ...interface{})
func (*RateLimitedLogger) Debugf ¶
func (logger *RateLimitedLogger) Debugf(format string, args ...interface{})
func (*RateLimitedLogger) Debugln ¶
func (logger *RateLimitedLogger) Debugln(args ...interface{})
func (*RateLimitedLogger) Error ¶
func (logger *RateLimitedLogger) Error(args ...interface{})
func (*RateLimitedLogger) Errorf ¶
func (logger *RateLimitedLogger) Errorf(format string, args ...interface{})
func (*RateLimitedLogger) Errorln ¶
func (logger *RateLimitedLogger) Errorln(args ...interface{})
func (*RateLimitedLogger) Force ¶
func (logger *RateLimitedLogger) Force() *RateLimitedLogger
Force forces the next log to be processed. Note that this does not force the log to be written since that is also dependent on the logging level.
func (*RateLimitedLogger) Info ¶
func (logger *RateLimitedLogger) Info(args ...interface{})
func (*RateLimitedLogger) Infof ¶
func (logger *RateLimitedLogger) Infof(format string, args ...interface{})
func (*RateLimitedLogger) Infoln ¶
func (logger *RateLimitedLogger) Infoln(args ...interface{})
func (*RateLimitedLogger) Print ¶
func (logger *RateLimitedLogger) Print(args ...interface{})
func (*RateLimitedLogger) Printf ¶
func (logger *RateLimitedLogger) Printf(format string, args ...interface{})
func (*RateLimitedLogger) Println ¶
func (logger *RateLimitedLogger) Println(args ...interface{})
func (*RateLimitedLogger) Warn ¶
func (logger *RateLimitedLogger) Warn(args ...interface{})
func (*RateLimitedLogger) Warnf ¶
func (logger *RateLimitedLogger) Warnf(format string, args ...interface{})
func (*RateLimitedLogger) Warning ¶
func (logger *RateLimitedLogger) Warning(args ...interface{})
func (*RateLimitedLogger) Warningf ¶
func (logger *RateLimitedLogger) Warningf(format string, args ...interface{})
func (*RateLimitedLogger) Warningln ¶
func (logger *RateLimitedLogger) Warningln(args ...interface{})
func (*RateLimitedLogger) Warnln ¶
func (logger *RateLimitedLogger) Warnln(args ...interface{})
func (*RateLimitedLogger) WithError ¶
func (logger *RateLimitedLogger) WithError(err error) *RateLimitedLogger
WithError adds an error as single field (using the key defined in ErrorKey) to the RateLimitedLogger.
func (*RateLimitedLogger) WithField ¶
func (logger *RateLimitedLogger) WithField(key string, value interface{}) *RateLimitedLogger
WithField adds a single field to the RateLimitedLogger.
func (*RateLimitedLogger) WithFields ¶
func (logger *RateLimitedLogger) WithFields(fields logrus.Fields) *RateLimitedLogger
WithFields adds a map of fields to the RateLimitedLogger.
type RateLimitedLoggerOpt ¶
type RateLimitedLoggerOpt func(*RateLimitedLogger)
func OptInterval ¶
func OptInterval(d time.Duration) RateLimitedLoggerOpt
func OptLogger ¶
func OptLogger(l *logrus.Logger) RateLimitedLoggerOpt