formatters

package
v0.0.0-...-9b2170e Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2021 License: ISC Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const JSONFormatter jsonFormatter = "JSONFormatter"

Formatter that returns log message in form of JSON.

Variables

This section is empty.

Functions

func DecolorizeBuffer

func DecolorizeBuffer(text []byte) []byte

Returns text without color.

func DecolorizeString

func DecolorizeString(text string) string

Returns text without color.

func LenPrintableText

func LenPrintableText(text string) int

Returns utf8.RuneCountInString of text without ANSI color codes.

func PaintBuffer

func PaintBuffer(color Color, text []byte) []byte

Returns []byte prepended by ANSI color code and appended by ANSI color reset code.

func PaintText

func PaintText(color Color, text string) string

Returns text prepended by ANSI color code and appended by ANSI color reset code.

Types

type Color

type Color string
const (
	ANSIReset       Color = "\033[0m"
	ANSIColorRed    Color = "\033[31m"
	ANSIColorGreen  Color = "\033[32m"
	ANSIColorYellow Color = "\033[33m"
	ANSIColorBlue   Color = "\033[34m"
	ANSIColorPurple Color = "\033[35m"
	ANSIColorCyan   Color = "\033[36m"
	ANSIColorWhite  Color = "\033[37m"
	ANSIColorGray   Color = "\033[90m"
	ANSIFontBold    Color = "\033[1m"

	ColorTrace Color = ANSIColorGray
	ColorDebug Color = ANSIColorCyan
	ColorInfo  Color = ANSIColorGreen
	ColorWarn  Color = ANSIColorYellow
	ColorError Color = ANSIColorRed
	ColorFatal Color = ANSIFontBold + ANSIColorRed
)

type Log

type Log struct {
	LevelCode int                 `json:"levelCode"`
	Level     string              `json:"level"`
	Location  string              `json:"location"`
	Message   string              `json:"message"`
	Tags      map[string][]string `json:"tags"`
	DateUnix  time.Time           `json:"date"`
}

Log model returned by JSONFormatter.

type LogFormatter

type LogFormatter interface {
	// Returns formatted log message in []byte.
	GetOutput(level int, message string, tags map[string][]string, calldepth int) []byte
}

Carries log message formatting and marshalling logic.

func Default

func Default() LogFormatter

Returns default instance of Formatter with time.RFC822 as timeFormat. Formatter that returns log message in form of colorized plain text rows of fixed length.

func New

func New(timeFormat string) LogFormatter

Returns default instance of Formatter with timeFormat. Formatter that returns log message in form of colorized plain text rows of fixed length.

Jump to

Keyboard shortcuts

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