Documentation
¶
Index ¶
- func ContextWithLogger(ctx context.Context, l DDSourceLogger) context.Context
- func Shim(ctx context.Context, l DDSourceLogger) context.Context
- type DDSourceLogger
- type Field
- func Any(key string, value interface{}) Field
- func Base64(key string, value []byte) Field
- func Bool(key string, value bool) Field
- func Byte(key string, value byte) Field
- func Bytes(key string, value []byte, limit int) Field
- func Dur(key string, value time.Duration, truncate ...time.Duration) Field
- func Duration(key string, value time.Duration) Field
- func Durations(key string, value []time.Duration) Field
- func ErrorField(err error) Field
- func ErrorWithStackField(err error) Field
- func Float(key string, val float64, format string) Field
- func Float32(key string, value float32) Field
- func Float64(key string, val float64) Field
- func Int(key string, value int) Field
- func Int32(key string, value int32) Field
- func Int32s(key string, value []int32) Field
- func Int64(key string, value int64) Field
- func Int64s(key string, value []int64) Field
- func Ints(key string, value []int) Field
- func Msec(key string, dur time.Duration) Field
- func NamedError(key string, err error) Field
- func Object(key string, value interface{}) Field
- func Org(orgID int64) Field
- func Org32(orgID int32) Field
- func Percent(key string, part, whole float64) Field
- func PercentInt(key string, part, whole int) Field
- func RichError(err error) Field
- func Skip() Field
- func String(key, value string) Field
- func Stringer(key string, value fmt.Stringer) Field
- func Stringers[T fmt.Stringer](key string, value []T) Field
- func Stringf(key, format string, args ...interface{}) Field
- func Strings(key string, value []string) Field
- func StructuredObject(key string, value zapcore.ObjectMarshaler) Field
- func Time(key string, value time.Time) Field
- func TraceField(ctx context.Context) Fielddeprecated
- func Uint(key string, value uint) Field
- func Uint32(key string, value uint32) Field
- func Uint32s(key string, value []uint32) Field
- func Uint64(key string, value uint64) Field
- func Uint64s(key string, value []uint64) Field
- func Uints(key string, value []uint) Field
- type UnwrapJoin
- type UnwrapMultierror
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 ¶
func Shim(ctx context.Context, l DDSourceLogger) context.Context
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 ¶
Field aliased here to make it easier to adopt this package
func ErrorWithStackField ¶
ErrorWithStackField writes an error. Prints message and stack if available.
func Msec ¶
Msec writes a duration in milliseconds. If the time is <10msec, it is given to one decimal point.
func NamedError ¶
NamedError writes an error with a custom name.
func PercentInt ¶
PercentInt writes out a percent out of 100%.
func RichError ¶
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 Stringer ¶
Stringer writes the output of the value's String method. The Stringer's String method is called lazily.
func Stringers ¶
Stringers writes the output of the value's String methods. The Stringer's String methods are called lazily.
func Stringf ¶
Stringf writes fmt.Sprintf(format, args...). It is evaluated lazily, only if the log message is going to be emitted.
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 TraceField
deprecated
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