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")
ErrUnsupportedKeyType is returned by Encoder methods if a key has an unsupported type.
var ErrUnsupportedValueType = errors.New("unsupported value type")
ErrUnsupportedValueType 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 Decoder ¶ added in v0.9.14
type Decoder struct {
// contains filtered or unexported fields
}
A Decoder reads and decodes logfmt records from an input stream.
func NewDecoder ¶ added in v0.9.14
NewDecoder returns a new decoder that reads from r.
The decoder introduces its own buffering and may read data from r beyond the logfmt records requested.
func (*Decoder) Err ¶ added in v0.9.14
Err returns the first non-EOF error that was encountered by the Scanner.
func (*Decoder) Key ¶ added in v0.9.14
Key returns the most recent key found by a call to ScanKeyval. The returned slice may point to internal buffers and is only valid until the next call to ScanRecord. It does no allocation.
func (*Decoder) ScanKeyval ¶ added in v0.9.14
ScanKeyval advances the Decoder to the next key/value pair of the current record, which can then be retrieved with the Key and Value methods. It returns false when decoding stops, either by reaching the end of the current record or an error.
func (*Decoder) ScanRecord ¶ added in v0.9.14
ScanRecord advances the Decoder to the next record, which can then be parsed with the ScanKeyval method. It returns false when decoding stops, either by reaching the end of the input or an error. After ScanRecord returns false, the Err method will return any error that occurred during decoding, except that if it was io.EOF, Err will return nil.
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 ¶
MarshalerError represents an error encountered while marshaling a value.
func (*MarshalerError) Error ¶
func (e *MarshalerError) Error() string
type SyntaxError ¶ added in v0.9.14
A SyntaxError represents a syntax error in the logfmt input stream.
func (*SyntaxError) Error ¶ added in v0.9.14
func (e *SyntaxError) Error() string