log

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithLogger

func ContextWithLogger(ctx context.Context, l DDSourceLogger) context.Context

ContextWithLogger implements log.ContextWithLogger from dd-source

func Shim

Shim is just ContextWithLogger with a different name, used to document which specific code can be deleted when this library is moved to dd-source.

This should be called immediately upon receiving a logger passed in from code that lives in dd-source.

Types

type DDSourceLogger

type DDSourceLogger interface {
	With(fields ...Field) DDSourceLogger

	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 ...any)
	Infof(msg string, params ...any)
	Warnf(msg string, params ...any)
	Errorf(msg string, params ...any)
	Panicf(msg string, params ...any)
	Fatalf(msg string, params ...any)
}

DDSourceLogger is a copy of the interface at https://github.com/DataDog/dd-source/blob/main/libs/go/log/logger.go

func FromContext

func FromContext(ctx context.Context) DDSourceLogger

FromContext implements log.FromContext from dd-source.

Warning

This will _not_ work to extract a log.Logger from a context provided by code that lives in dd-source.

This will _only_ extract a DDSourceLogger generated within this (datadog-saist) library!

If you need a log.Logger from dd-source and you haven't already converted one to a DDSourceLogger, you MUST modify your function to pass one in directly and then use Shim.

If no logger was present, a default one will be newly allocated.

func NewDefaultLogger

func NewDefaultLogger() DDSourceLogger

NewDefaultLogger Creates a new zap Logger.

Warning

This may leak memory, as it is never flushed. Avoid calling this when possible.

func NoopLogger

func NoopLogger() DDSourceLogger

NoopLogger implements log.NoopLogger from dd-source

type Field

type Field = zapcore.Field

Field aliased here to make it easier to adopt this package

func Any

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

Any takes a value and chooses the best way to represent it as a field

func Base64

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

Base64 writes value encoded as base64.

func Bool

func Bool(key string, value bool) Field

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

func Byte

func Byte(key string, value byte) Field

Byte writes a single byte as its ascii representation.

func Bytes

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

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

func Dur

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

Dur writes a duration field truncated to the given duration.

func Duration

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

Duration using its standard String() representation.

func Durations

func Durations(key string, value []time.Duration) Field

Durations writes a slice of durations as an array.

func ErrorField

func ErrorField(err error) Field

ErrorField writes an error.

func ErrorWithStackField

func ErrorWithStackField(err error) Field

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

func Float

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

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

func Float32

func Float32(key string, value float32) Field

Float32 writes a float32 value.

func Float64

func Float64(key string, val float64) Field

Float64 writes a float value.

func Int

func Int(key string, value int) Field

Int writes an int value.

func Int32

func Int32(key string, value int32) Field

Int32 writes an int32 value.

func Int32s

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

Int32s writes a slice of int32s.

func Int64

func Int64(key string, value int64) Field

Int64 writes an int64 value.

func Int64s

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

Int64s writes an int64 slice as an array.

func Ints

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

Ints writes an int slice as an array.

func Msec

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

func NamedError(key string, err error) Field

NamedError writes an error with a custom name.

func Object

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

Object writes an object with "%+v".

func Org

func Org(orgID int64) Field

Org writes an orgID with the common key "org_id".

func Org32

func Org32(orgID int32) Field

Org32 writes an int32 orgID with the common key "org_id".

func Percent

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

Percent writes out a percent out of 100%.

func PercentInt

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

PercentInt writes out a percent out of 100%.

func RichError

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

func Skip() Field

Skip returns a no-op field

func String

func String(key, value string) Field

String writes a string value.

func Stringer

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

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

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

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

Strings writes a slice of strings.

func StructuredObject

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

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

Time writes the value as a Unix timestamp.

func TraceField deprecated

func TraceField(ctx context.Context) Field

Deprecated: Use pkg/log/tracing Trace Logger instead

func Uint

func Uint(key string, value uint) Field

Uint writes a uint.

func Uint32

func Uint32(key string, value uint32) Field

Uint32 writes a uint32.

func Uint32s

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

Uint32s writes a uint32 slice as an array.

func Uint64

func Uint64(key string, value uint64) Field

Uint64 writes a uint64.

func Uint64s

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

Uint64s writes a uint64 slice as an array.

func Uints

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

Uints writes a uint slice as an array.

type UnwrapJoin

type UnwrapJoin interface {
	Unwrap() []error
}

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

type UnwrapMultierror

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