jsonlogfmt

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2020 License: MIT Imports: 9 Imported by: 0

README

jsonlogfmt

This package provides an io.Reader implementation that converts from logfmt data to json

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InferFields

func InferFields(t reflect.Type) map[string]Type

InferFields takes a struct type, and converts it into a set of fields to be used in a schema. This function will panic if t is not a struct type or a pointer to a struct

func ParseValue

func ParseValue(t Type, s string) (interface{}, error)

ParseValue parses a string as the provided type

Types

type Reader

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

Reader converts logfmt data to json

func NewReader

func NewReader(r io.Reader, schema Schema) *Reader

NewReader returns a Reader that converts from logfmt to json.

func (*Reader) Read

func (r *Reader) Read(data []byte) (int, error)

Read implements io.Reader

func (*Reader) ReadMap

func (r *Reader) ReadMap() (map[string]interface{}, error)

ReadMap reads the next logfmt record, converts the fields according to the schema and returns them in a map

func (*Reader) SetIndent

func (r *Reader) SetIndent(prefix, indent string)

SetIndent calls SetIndent on the json.Encoder

type Schema

type Schema struct {
	Strict bool // only output fields in the schema
	Fields map[string]Type
}

Schema describes a set of fields and their types

func (Schema) Parse

func (s Schema) Parse(key, value string) (interface{}, error)

Parse the key/value pair

func (*Schema) Set

func (s *Schema) Set(value string) error

Set implements flag.Value and allows expects fields with the following syntax name:type (see ParseType for valid types)

func (Schema) String

func (s Schema) String() string

String returns a string representation of the schema.

func (Schema) Valid

func (s Schema) Valid(key string) bool

Valid returns true if the key should be included in the output

type Type

type Type int

Type is the type of a field

const (
	NumberType Type = iota
	DurationType
	StringType
	TimeType
	BoolType
)

func ParseType

func ParseType(s string) (Type, error)

ParseType parses the string representation of a type. Currently: number, duration, string, bool

func (Type) String

func (t Type) String() string

String returns the string representation of a type

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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