Documentation
¶
Index ¶
- Variables
- func CheckFatal(location string, err error)
- func InitLogger(cfg *logging.Config)
- func NewDefaultLogger(l level.Value, format string) log.Logger
- func WarnExperimentalUse(feature string)
- func WithSourceIPs(sourceIPs string, l log.Logger) log.Logger
- func WithTraceID(traceID string, l log.Logger) log.Logger
- type RateLimitedLogger
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // Logger is a shared go-kit logger. // TODO: Change all components to take a non-global logger via their constructors. // Prefer accepting a non-global logger as an argument. Logger = log.NewNopLogger() )
Functions ¶
func CheckFatal ¶
CheckFatal prints an error and exits with error code 1 if err is non-nil
func InitLogger ¶
InitLogger initialises the global gokit logger (util_log.Logger) and overrides the default logger for the server.
Example ¶
Check that debug lines are correctly filtered out.
package main
import (
"flag"
"os"
"time"
gokitlog "github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/udmire/observability-operator/pkg/configs/logging"
"github.com/udmire/observability-operator/pkg/utils/log"
)
func main() {
// Kludge a couple of things so we can do tests repeatably.
saveStderr := os.Stderr
os.Stderr = os.Stdout
saveTimestamp := gokitlog.DefaultTimestampUTC
gokitlog.DefaultTimestampUTC = gokitlog.TimestampFormat(
func() time.Time { return time.Unix(0, 0).UTC() },
time.RFC3339Nano,
)
cfg := logging.Config{Level: "info"}
cfg.RegisterFlags(&flag.FlagSet{})
log.InitLogger(&cfg)
level.Info(log.Logger).Log("test", "1")
level.Debug(log.Logger).Log("test", "2 - should not print")
os.Stderr = saveStderr
gokitlog.DefaultTimestampUTC = saveTimestamp
}
Output: ts=1970-01-01T00:00:00Z caller=log_test.go:30 level=info test=1
func NewDefaultLogger ¶
NewDefaultLogger creates a new gokit logger with the configured level and format
func WarnExperimentalUse ¶
func WarnExperimentalUse(feature string)
WarnExperimentalUse logs a warning and increments the experimental features metric.
func WithSourceIPs ¶
WithSourceIPs returns a Logger that has information about the source IPs in its details.
Types ¶
type RateLimitedLogger ¶
type RateLimitedLogger struct {
// contains filtered or unexported fields
}
RateLimitedLogger implements log.Logger and permits only a single log invocation every interval.
func NewRateLimitedLogger ¶
func (RateLimitedLogger) Log ¶
func (r RateLimitedLogger) Log(keyvals ...interface{}) error
Click to show internal directories.
Click to hide internal directories.