json

package
v1.0.100 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2021 License: MIT Imports: 6 Imported by: 1

Documentation

Overview

Package json implements a json formatter which implements the Formatter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// FileSegs specifies how many segments from last of the File field of a
	// Record will be formatted. The separator of segment is '/'.
	// If FileSegs is not specified, 0 is used which means all.
	FileSegs int
	// PkgSegs specifies how many segments from last of the Pkg field of a
	// Record will be formatted. The separator of segment is '/'.
	// If PkgSegs is not specified, 0 is used which means all.
	PkgSegs int
	// FuncSegs specifies how many segments from last of the Func field of a
	// Record will be formatted. The separator of segment is '.'.
	// If FuncSegs is not specified, 0 is used which means all.
	FuncSegs int
	// Omit specifies which fields of a Record will be omitted.
	Omit OmitBits
	// OmitEmpty specifies which fields of a Record will be omitted when they are
	// the zero value of their type.
	OmitEmpty OmitBits
	// MinBufSize is the initial size of the internal buf of a formatter.
	// MinBufSize must NOT be negative. If it is not specified, 384 is used.
	MinBufSize int
}

A Config is used to configure a json formatter.

func NewConfig

func NewConfig() Config

type Formatter

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

A Formatter implements the interface iface.Formatter.

All methods of a Formatter are concurrency safe. A Formatter MUST be created with New.

func New

func New(config Config) *Formatter

New creates a new Formatter with the config.

func (*Formatter) Config

func (formatter *Formatter) Config() Config

Config returns the Config of the Formatter.

func (*Formatter) Format

func (formatter *Formatter) Format(record *iface.Record) []byte

Format implements the interface Formatter. It formats a Record.

func (*Formatter) SetConfig

func (formatter *Formatter) SetConfig(config Config)

SetConfig sets the config to the Formatter.

func (*Formatter) UpdateConfig

func (formatter *Formatter) UpdateConfig(fn func(Config) Config)

UpdateConfig calls the fn with the Config of the Formatter, and then sets the returned Config to the Formatter. The fn must NOT be nil.

Do NOT call any method of the Formatter or the Logger within the fn, or it may deadlock.

type OmitBits

type OmitBits int

The OmitBits defines the flag type that is used to omit fields of a Record.

const (
	Time OmitBits = 0x1 << iota
	Level
	File
	Line
	Pkg
	Func
	Msg
	Prefix
	Context
	Mark
	Aux = Prefix | Context | Mark
)

All available flags here. If a flag is set, the corresponding field of a Record will be omitted.

Jump to

Keyboard shortcuts

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