Documentation ¶
Overview ¶
Package logfmt implements utilities to marshal and unmarshal data in the logfmt format. The logfmt format records key/value pairs in a way that balances readability for humans and simplicity of computer parsing. It is most commonly used as a more human friendly alternative to JSON for structured logging.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidKey = errors.New("invalid key")
ErrInvalidKey is returned by Marshal functions and Encoder methods if a key contains an invalid character.
var ErrNilKey = errors.New("nil key")
ErrNilKey is returned by Marshal functions and Encoder methods if a key is a nil interface or pointer value.
var ErrUnsupportedKeyType = errors.New("unsupported key type")
ErrUnsupportedType is returned by Encoder methods if a key has an unsupported type.
var ErrUnsupportedValueType = errors.New("unsupported value type")
ErrUnsupportedType is returned by Encoder methods if a value has an unsupported type.
Functions ¶
func MarshalKeyvals ¶
MarshalKeyvals returns the logfmt encoding of keyvals, a variadic sequence of alternating keys and values.
Types ¶
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
An Encoder writes logfmt data to an output stream.
func NewEncoder ¶
NewEncoder returns a new encoder that writes to w.
func (*Encoder) EncodeKeyval ¶
EncodeKeyval writes the logfmt encoding of key and value to the stream. A single space is written before the second and subsequent keys in a record. Nothing is written if a non-nil error is returned.
type MarshalerError ¶
func (*MarshalerError) Error ¶
func (e *MarshalerError) Error() string