2021-01-31 23:10:16 +00:00
|
|
|
package log
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
2021-09-27 14:57:40 +00:00
|
|
|
|
|
|
|
"github.com/go-kit/log"
|
2021-01-31 23:10:16 +00:00
|
|
|
)
|
|
|
|
|
2021-07-07 13:05:04 +00:00
|
|
|
// A Valuer generates a log value. When passed to With, WithPrefix, or
|
|
|
|
// WithSuffix in a value element (odd indexes), it represents a dynamic
|
|
|
|
// value which is re-evaluated with each log event.
|
2021-09-27 14:57:40 +00:00
|
|
|
type Valuer = log.Valuer
|
2021-01-31 23:10:16 +00:00
|
|
|
|
|
|
|
// Timestamp returns a timestamp Valuer. It invokes the t function to get the
|
|
|
|
// time; unless you are doing something tricky, pass time.Now.
|
|
|
|
//
|
|
|
|
// Most users will want to use DefaultTimestamp or DefaultTimestampUTC, which
|
|
|
|
// are TimestampFormats that use the RFC3339Nano format.
|
|
|
|
func Timestamp(t func() time.Time) Valuer {
|
2021-09-27 14:57:40 +00:00
|
|
|
return log.Timestamp(t)
|
2021-01-31 23:10:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TimestampFormat returns a timestamp Valuer with a custom time format. It
|
|
|
|
// invokes the t function to get the time to format; unless you are doing
|
|
|
|
// something tricky, pass time.Now. The layout string is passed to
|
|
|
|
// Time.Format.
|
|
|
|
//
|
|
|
|
// Most users will want to use DefaultTimestamp or DefaultTimestampUTC, which
|
|
|
|
// are TimestampFormats that use the RFC3339Nano format.
|
|
|
|
func TimestampFormat(t func() time.Time, layout string) Valuer {
|
2021-09-27 14:57:40 +00:00
|
|
|
return log.TimestampFormat(t, layout)
|
2021-01-31 23:10:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Caller returns a Valuer that returns a file and line from a specified depth
|
|
|
|
// in the callstack. Users will probably want to use DefaultCaller.
|
|
|
|
func Caller(depth int) Valuer {
|
2021-09-27 14:57:40 +00:00
|
|
|
return log.Caller(depth)
|
2021-01-31 23:10:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
// DefaultTimestamp is a Valuer that returns the current wallclock time,
|
|
|
|
// respecting time zones, when bound.
|
2021-09-27 14:57:40 +00:00
|
|
|
DefaultTimestamp = log.DefaultTimestamp
|
2021-01-31 23:10:16 +00:00
|
|
|
|
|
|
|
// DefaultTimestampUTC is a Valuer that returns the current time in UTC
|
|
|
|
// when bound.
|
2021-09-27 14:57:40 +00:00
|
|
|
DefaultTimestampUTC = log.DefaultTimestampUTC
|
2021-01-31 23:10:16 +00:00
|
|
|
|
|
|
|
// DefaultCaller is a Valuer that returns the file and line where the Log
|
|
|
|
// method was invoked. It can only be used with log.With.
|
2021-09-27 14:57:40 +00:00
|
|
|
DefaultCaller = log.DefaultCaller
|
2021-01-31 23:10:16 +00:00
|
|
|
)
|