clilog

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2021 License: Apache-2.0 Imports: 9 Imported by: 3

Documentation

Overview

Package clilog is a github.com/go-kit/kit/log logger implementation suitable for CLI tools. Main goal is to log in human readable ways e.g:

* No special sign escaping. * No key printing. * Values separated with ': ' * Support for pretty printing multi errors (including nested ones) in format of (<something>: <err1>; <err2>; ...; <errN>) * TODO(bwplotka): Support for multiple multilines. This implementation allows CLI to use github.com/go-kit/kit/log enabled libraries in CLI friendly way.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedKeyType = errors.New("unsupported key type")

ErrUnsupportedKeyType is returned by Encoder methods if a key has an unsupported type.

View Source
var ErrUnsupportedValueType = errors.New("unsupported value type")

ErrUnsupportedValueType is returned by Encoder methods if a value has an unsupported type.

Functions

func MarshalKeyvals

func MarshalKeyvals(keyvals ...interface{}) ([]byte, error)

MarshalKeyvals returns the clilog encoding of keyvals, a variadic sequence of alternating keys and values.

func New

func New(w io.Writer) log.Logger

New returns a logger that encodes keyvals to the Writer in CLI friendly format. Each log event produces no more than one call to w.Write. The passed Writer must be safe for concurrent use by multiple goroutines if the returned Logger will be used concurrently.

Types

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

An Encoder writes clilog data to an output stream.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new clilog Encoder that writes to w.

func (*Encoder) EncodeKeyval

func (enc *Encoder) EncodeKeyval(_, value interface{}) error

EncodeKeyval writes the clilog 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.

func (*Encoder) EncodeKeyvals

func (enc *Encoder) EncodeKeyvals(keyvals ...interface{}) error

EncodeKeyvals writes the logfmt encoding of keyvals to the stream. Keyvals is a variadic sequence of alternating keys and values. Keys of unsupported type are skipped along with their corresponding value. Values of unsupported type or that cause a MarshalerError are replaced by their error but do not cause EncodeKeyvals to return an error. If a non-nil error is returned some key/value pairs may not have be written.

func (*Encoder) EndRecord

func (enc *Encoder) EndRecord() error

EndRecord ends the log record.

func (*Encoder) Reset

func (enc *Encoder) Reset()

Reset resets the Encoder to the beginning of a new record.

type MarshalerError

type MarshalerError struct {
	Type reflect.Type
	Err  error
}

MarshalerError represents an error encountered while marshaling a value.

func (*MarshalerError) Error

func (e *MarshalerError) Error() string

Jump to

Keyboard shortcuts

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