log

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

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

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

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 Bool

func Bool(key string, val bool) Field

Bool constructs a Field with the given key and value. Bools are marshaled lazily.

func Duration

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

Duration constructs a Field with the given key and value. It represents durations as an integer number of nanoseconds.

func Error

func Error(err error) Field

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

func Float64(key string, val float64) Field

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 Int

func Int(key string, val int) Field

Int constructs a Field with the given key and value. Marshaling ints is lazy.

func Int64

func Int64(key string, val int64) Field

Int64 constructs a Field with the given key and value. Like ints, int64s are marshaled lazily.

func Nest

func Nest(key string, fields ...Field) Field

Nest takes a key and a variadic number of Fields and creates a nested namespace.

func Object

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

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 Ptr

func Ptr(key string, val interface{}) Field

func Skip

func Skip() Field

Skip constructs a no-op Field.

func String

func String(key string, val string) Field

String constructs a Field with the given key and value.

func Stringer

func Stringer(key string, val fmt.Stringer) Field

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

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

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.

func Type

func Type(key string, val interface{}) Field

func Uint

func Uint(key string, val uint) Field

Uint constructs a Field with the given key and value.

func Uint64

func Uint64(key string, val uint64) Field

Uint64 constructs a Field with the given key and value.

func Uintptr

func Uintptr(key string, val uintptr) Field

Uintptr constructs a Field with the given key and value.

func (Field) KV

func (f Field) KV() (string, string)

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
}

func New

func New(fields ...Field) Logger

New creates a new standard logger

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL