Documentation ¶
Index ¶
- type Field
- func Base64(key string, val []byte) Field
- func Bool(key string, val bool) Field
- func Duration(key string, val time.Duration) Field
- func Error(err error) Field
- func Float64(key string, val float64) Field
- func Int(key string, val int) Field
- func Int64(key string, val int64) Field
- func Nest(key string, fields ...Field) Field
- func Object(key string, val interface{}) Field
- func Ptr(key string, val interface{}) Field
- func Skip() Field
- func String(key string, val string) Field
- func Stringer(key string, val fmt.Stringer) Field
- func Time(key string, val time.Time) Field
- func Type(key string, val interface{}) Field
- func Uint(key string, val uint) Field
- func Uint64(key string, val uint64) Field
- func Uintptr(key string, val uintptr) Field
- type Logger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
A Field is a marshaling operation used to add a key-value pair to a logger's context. Most fields are lazily marshaled, so it's inexpensive to add fields to disabled debug-level log statements.
func Base64 ¶
Base64 constructs a field that encodes the given value as a padded base64 string. The byte slice is converted to a base64 string eagerly.
func Duration ¶
Duration constructs a Field with the given key and value. It represents durations as an integer number of nanoseconds.
func Error ¶
Error constructs a Field that lazily stores err.Error() under the key "error". If passed a nil error, the field is a no-op.
func Float64 ¶
Float64 constructs a Field with the given key and value. The way the floating-point value is represented is encoder-dependent, so marshaling is necessarily lazy.
func Int64 ¶
Int64 constructs a Field with the given key and value. Like ints, int64s are marshaled lazily.
func Object ¶
Object constructs a field with the given key and an arbitrary object. It uses an encoding-appropriate, reflection-based function to lazily serialize nearly any object into the logging context, but it's relatively slow and allocation-heavy.
If encoding fails (e.g., trying to serialize a map[int]string to JSON), Object includes the error message in the final log output.
func Stringer ¶
Stringer constructs a Field with the given key and the output of the value's String method. The Stringer's String method is called lazily.
func Time ¶
Time constructs a Field with the given key and value. It represents a time.Time as a floating-point number of seconds since epoch. Conversion to a float64 happens eagerly.
type Logger ¶
type Logger interface { // Info outputs an info log message Info(s string, fields ...Field) // Warn outputs a warning log message Warn(s string, fields ...Field) // Error outputs an error log message Error(s string, fields ...Field) // Progress tracks progresses of r Progress(s string, r io.Reader, size ...int64) io.ReadCloser }