log

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FieldK8sTypeKey          = "k8s_type"
	FieldCountKey            = "count"
	FieldNodeTypeKey         = "node_type"
	FieldVertexTypeKey       = "vertex_type"
	FieldClusterKey          = "cluster"
	FieldComponentKey        = "component"
	FieldRunIDKey            = "run_id"
	FieldTeamKey             = "team"
	FieldServiceKey          = "service"
	FieldAppKey              = "app"
	FieldIngestorPipelineKey = "ingestor_pipeline"
	FieldDumpPipelineKey     = "dump_pipeline"
	FieldPathKey             = "path"
	FieldEntityKey           = "entity"
)
View Source
const (
	ContextFieldRunID contextKey = iota
	ContextFieldCluster
	ContextFieldComponent
)
View Source
const DefaultLevel = LevelInfo

DefaultLevel is the logging level if nothing is configured.

Variables

View Source
var (
	DefaultRemovedFields = []string{FieldTeamKey, FieldServiceKey, FieldAppKey, FieldRunIDKey, FieldClusterKey, FieldComponentKey, spanIDKey, traceIDKey}
)

Functions

func FieldCluster added in v1.6.0

func FieldCluster(cluster string) string

func FieldComponent added in v1.6.0

func FieldComponent(component string) string

func FieldCount added in v1.6.0

func FieldCount(count int) string

func FieldDumpPipeline added in v1.6.0

func FieldDumpPipeline(dumpPipeline string) string

func FieldIngestorPipeline added in v1.6.0

func FieldIngestorPipeline(ingestorPipeline string) string

func FieldK8sType added in v1.6.0

func FieldK8sType(k8sType string) string

func FieldNodeType added in v1.6.0

func FieldNodeType(nodeType string) string

func FieldRunID added in v1.6.0

func FieldRunID(runID string) string

func FieldService added in v1.6.0

func FieldService(service string) string

func FieldTeam added in v1.6.0

func FieldTeam(team string) string

func FieldVertexType added in v1.6.0

func FieldVertexType(vertexType string) string

func GetClusterFromContext added in v1.6.0

func GetClusterFromContext(ctx context.Context) string

func GetComponentFromContext added in v1.6.0

func GetComponentFromContext(ctx context.Context) string

func GetRunIDFromContext added in v1.6.0

func GetRunIDFromContext(ctx context.Context) string

func InitLogger added in v1.6.0

func InitLogger()

func NewKeyValueEncoder added in v1.6.0

func NewKeyValueEncoder(cfg zapcore.EncoderConfig) (zapcore.Encoder, error)

NewKeyValueEncoder creates a key/value encoder that emits logs with a very basic "key=value" formatting.

func SpanSetDefaultField added in v1.6.0

func SpanSetDefaultField(ctx context.Context, span ddtrace.Span)

Types

type Field added in v1.6.0

type Field = zapcore.Field

Field aliased here to make it easier to adopt this package

func Base64 added in v1.6.0

func Base64(key string, value []byte) Field

Base64 writes value encoded as base64.

func Bool added in v1.6.0

func Bool(key string, value bool) Field

Bool writes "true" or "false" for value.

func Byte added in v1.6.0

func Byte(key string, value byte) Field

Byte writes a single byte as its ascii representation.

func Bytes added in v1.6.0

func Bytes(key string, value []byte, limit int) Field

Bytes writes the []bytes as a string, up to limit characters.

func Dur added in v1.6.0

func Dur(key string, value time.Duration, truncate ...time.Duration) Field

Dur writes a duration field truncated to the given duration.

func Duration added in v1.6.0

func Duration(key string, value time.Duration) Field

Duration using its standard String() representation.

func ErrorField added in v1.6.0

func ErrorField(err error) Field

ErrorField writes an error.

func ErrorWithStackField added in v1.6.0

func ErrorWithStackField(err error) Field

ErrorWithStackField writes an error. Prints message and stack if available.

func Float added in v1.6.0

func Float(key string, val float64, fmt string) Field

Float writes a float64 value using the printf-style fmt string.

func Float32 added in v1.6.0

func Float32(key string, value float32) Field

Float32 writes a float32 value.

func Float64 added in v1.6.0

func Float64(key string, val float64) Field

Float64 writes a float value.

func Int added in v1.6.0

func Int(key string, value int) Field

Int writes an int value.

func Int32 added in v1.6.0

func Int32(key string, value int32) Field

Int32 writes an int32 value.

func Int32s added in v1.6.0

func Int32s(key string, value []int32) Field

Int32s writes a slice of int32s.

func Int64 added in v1.6.0

func Int64(key string, value int64) Field

Int64 writes an int64 value.

func Int64s added in v1.6.0

func Int64s(key string, value []int64) Field

Int64s writes an int64 slice as an array.

func Ints added in v1.6.0

func Ints(key string, value []int) Field

Ints writes an int slice as an array.

func Msec added in v1.6.0

func Msec(key string, dur time.Duration) Field

Msec writes a duration in milliseconds. If the time is <10msec, it is given to one decimal point.

func NamedError added in v1.6.0

func NamedError(key string, err error) Field

NamedError writes an error with a custom name.

func Object added in v1.6.0

func Object(key string, value interface{}) Field

Object writes an object with "%+v".

func Percent added in v1.6.0

func Percent(key string, part, whole float64) Field

Percent writes out a percent out of 100%.

func PercentInt added in v1.6.0

func PercentInt(key string, part, whole int) Field

PercentInt writes out a percent out of 100%.

func RichError added in v1.6.0

func RichError(err error) Field

RichError writes an error in the standard format expected by Datadog:

  • type of error in `error.kind`
  • `err.Error()` in `error.message`
  • stack trace from the first error that has one in the chain of wrapped errors starting from err in `error.stack`, or RichError caller stack trace if no such stack trace was found.
  • RichError caller stack trace in `error.handling_stack` if a stack trace was found from err.

func Skip added in v1.6.0

func Skip() Field

Skip returns a no-op field

func String added in v1.6.0

func String(key, value string) Field

String writes a string value.

func Stringer added in v1.6.0

func Stringer(key string, value fmt.Stringer) Field

Stringer writes the output of the value's String method. The Stringer's String method is called lazily.

func Stringers added in v1.6.0

func Stringers[T fmt.Stringer](key string, value []T) Field

Stringers writes the output of the value's String methods. The Stringer's String methods are called lazily.

func Stringf added in v1.6.0

func Stringf(key, format string, args ...interface{}) Field

Stringf writes fmt.Sprintf(format, args...). It is evaluated lazily, only if the log message is going to be emitted.

func Strings added in v1.6.0

func Strings(key string, value []string) Field

Strings writes a slice of strings.

func StructuredObject added in v1.6.0

func StructuredObject(key string, value zapcore.ObjectMarshaler) Field

StructuredObject adds value as a structured object. value must implement zap.MarshalLogObject. Examples of such implementations can be found here: https://github.com/uber-go/zap/blob/9b86a50a3e27e0e12ccb6b47288de27df7fd3d5b/example_test.go#L176-L186

func Time added in v1.6.0

func Time(key string, value time.Time) Field

Time writes the value as a Unix timestamp.

func Uint added in v1.6.0

func Uint(key string, value uint) Field

Uint writes a uint.

func Uint32 added in v1.6.0

func Uint32(key string, value uint32) Field

Uint32 writes a uint32.

func Uint32s added in v1.6.0

func Uint32s(key string, value []uint32) Field

Uint32s writes a uint32 slice as an array.

func Uint64 added in v1.6.0

func Uint64(key string, value uint64) Field

Uint64 writes a uint64.

func Uint64s added in v1.6.0

func Uint64s(key string, value []uint64) Field

Uint64s writes a uint64 slice as an array.

func Uints added in v1.6.0

func Uints(key string, value []uint) Field

Uints writes a uint slice as an array.

type KubehoundLogger

type KubehoundLogger struct {
	LoggerI
}

type Level added in v1.6.0

type Level byte

Level of log emission. A logger at any level will ignore all levels below it in value.

const (
	LevelTrace Level = iota
	LevelDebug
	LevelInfo
	LevelWarn
	LevelError
	LevelPanic
	LevelFatal
)

Logging levels

func LevelFromString added in v1.6.0

func LevelFromString(str string) (Level, error)

LevelFromString returns the level for the given string. If the string is not valid, an error is returned.

func (Level) MarshalText added in v1.6.0

func (lvl Level) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler for Level.

func (Level) String added in v1.6.0

func (lvl Level) String() string

func (*Level) UnmarshalText added in v1.6.0

func (lvl *Level) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler for Level.

type LoggerI added in v1.6.0

type LoggerI interface {
	// With returns a child logger structured with the provided fields.
	// Fields added to the child don't affect the parent, and vice versa.
	With(fields ...Field) LoggerI

	Debug(msg string, fields ...Field)
	Info(msg string, fields ...Field)
	Warn(msg string, fields ...Field)
	Error(msg string, fields ...Field)
	Panic(msg string, fields ...Field)
	Fatal(msg string, fields ...Field)

	Debugf(msg string, params ...interface{})
	Infof(msg string, params ...interface{})
	Warnf(msg string, params ...interface{})
	Errorf(msg string, params ...interface{})
	Panicf(msg string, params ...interface{})
	Fatalf(msg string, params ...interface{})
}

func DefaultLogger added in v1.6.0

func DefaultLogger() LoggerI

DefaultLogger returns the global logger

func Logger added in v1.6.0

func Logger(ctx context.Context) LoggerI

func Trace

func Trace(ctx context.Context) LoggerI

Trace returns a wrapped default logger that automatically adds trace related ids to log output.

func TraceLogger added in v1.6.0

func TraceLogger(ctx context.Context, logger LoggerI) LoggerI

TraceLogger returns a wrapped version of logger that automatically adds trace related ids to log output. If Logger was not created by this package, the caller line number information will be incorrect.

type UnwrapJoin added in v1.6.0

type UnwrapJoin interface {
	Unwrap() []error
}

Interface to unwrap joined errors.Join https://pkg.go.dev/errors#Join

type UnwrapMultierror added in v1.6.0

type UnwrapMultierror interface {
	WrappedErrors() []error
}

Interface to unwrap joined multierror.Append https://pkg.go.dev/github.com/hashicorp/go-multierror#Error.WrappedErrors

Jump to

Keyboard shortcuts

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