log

package
v0.0.0-...-5af6bcd Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

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

func CheckFatal(location string, err error)

CheckFatal prints an error and exits with error code 1 if err is non-nil

func InitLogger

func InitLogger(cfg *logging.Config)

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

func NewDefaultLogger(l level.Value, format string) log.Logger

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

func WithSourceIPs(sourceIPs string, l log.Logger) log.Logger

WithSourceIPs returns a Logger that has information about the source IPs in its details.

func WithTraceID

func WithTraceID(traceID string, l log.Logger) log.Logger

WithTraceID returns a Logger that has information about the traceID 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 NewRateLimitedLogger(interval time.Duration, delegate log.Logger, now func() time.Time) RateLimitedLogger

func (RateLimitedLogger) Log

func (r RateLimitedLogger) Log(keyvals ...interface{}) error

Jump to

Keyboard shortcuts

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