json

package
v0.0.0-...-dad4d3c Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2023 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColorFormatter

type ColorFormatter interface {
	SprintfFunc() PrintfColorFunc
	SprintFunc() PrintColorFunc
}

ColorFormatter formats a color

type ColorFunc

type ColorFunc func(k, v interface{}) ColorFormatter

ColorFunc returns the color formatter

type Config

type Config struct {
	DisplayColor     bool
	PrettyFormatting bool
	Writer           io.Writer
}

Config is the configuration

type Formatter

type Formatter struct {
	// JSON key color. Default is `color.New(color.FgBlue, color.Bold)`.
	KeyColor ColorFormatter

	// JSON string value color. Default is `color.New(color.FgGreen, color.Bold)`.
	StringColor ColorFormatter

	// JSON boolean value color. Default is `color.New(color.FgYellow, color.Bold)`.
	BoolColor ColorFormatter

	// JSON number value color. Default is `color.New(color.FgCyan, color.Bold)`.
	NumberColor ColorFormatter

	// JSON null value color. Default is `color.New(color.FgBlack, color.Bold)`.
	NullColor ColorFormatter

	// ColorFn returns the color for given key and value
	ColorFn ColorFunc

	// Max length of JSON string value. When the value is 1 and over, string is truncated to length of the value.
	// Default is 0 (not truncated).
	StringMaxLength int

	// DisablePretty to disable formatting
	DisablePretty bool

	// Boolean to disable color. Default is false.
	DisabledColor bool

	// Indent space number. Default is 2.
	Indent int

	// Newline string. To print without new lines set it to empty string. Default is \n.
	Newline string
}

Formatter is a struct to format JSON data. `color` is github.com/fatih/color: https://github.com/fatih/color

func NewFormatter

func NewFormatter() *Formatter

NewFormatter returns a new formatter with following default values.

func (*Formatter) Marshal

func (f *Formatter) Marshal(v interface{}) ([]byte, error)

Marshal marshals and formats JSON data.

type Handler

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

Handler implementation.

func New

func New(writer io.Writer) *Handler

New handler.

func NewConfig

func NewConfig(config *Config) *Handler

NewConfig creates a handler with a config

func (*Handler) Handle

func (h *Handler) Handle(e *log.Entry)

Handle handles the log entry

type PrintColorFunc

type PrintColorFunc = func(a ...interface{}) string

PrintColorFunc prints the text in color

type PrintfColorFunc

type PrintfColorFunc = func(format string, a ...interface{}) string

PrintfColorFunc prints the value in color

Jump to

Keyboard shortcuts

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