value.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package log
  2. import (
  3. "time"
  4. "github.com/go-kit/log"
  5. )
  6. // A Valuer generates a log value. When passed to With, WithPrefix, or
  7. // WithSuffix in a value element (odd indexes), it represents a dynamic
  8. // value which is re-evaluated with each log event.
  9. type Valuer = log.Valuer
  10. // Timestamp returns a timestamp Valuer. It invokes the t function to get the
  11. // time; unless you are doing something tricky, pass time.Now.
  12. //
  13. // Most users will want to use DefaultTimestamp or DefaultTimestampUTC, which
  14. // are TimestampFormats that use the RFC3339Nano format.
  15. func Timestamp(t func() time.Time) Valuer {
  16. return log.Timestamp(t)
  17. }
  18. // TimestampFormat returns a timestamp Valuer with a custom time format. It
  19. // invokes the t function to get the time to format; unless you are doing
  20. // something tricky, pass time.Now. The layout string is passed to
  21. // Time.Format.
  22. //
  23. // Most users will want to use DefaultTimestamp or DefaultTimestampUTC, which
  24. // are TimestampFormats that use the RFC3339Nano format.
  25. func TimestampFormat(t func() time.Time, layout string) Valuer {
  26. return log.TimestampFormat(t, layout)
  27. }
  28. // Caller returns a Valuer that returns a file and line from a specified depth
  29. // in the callstack. Users will probably want to use DefaultCaller.
  30. func Caller(depth int) Valuer {
  31. return log.Caller(depth)
  32. }
  33. var (
  34. // DefaultTimestamp is a Valuer that returns the current wallclock time,
  35. // respecting time zones, when bound.
  36. DefaultTimestamp = log.DefaultTimestamp
  37. // DefaultTimestampUTC is a Valuer that returns the current time in UTC
  38. // when bound.
  39. DefaultTimestampUTC = log.DefaultTimestampUTC
  40. // DefaultCaller is a Valuer that returns the file and line where the Log
  41. // method was invoked. It can only be used with log.With.
  42. DefaultCaller = log.DefaultCaller
  43. )