structure

package
v0.0.0-...-eb16fb7 Latest Latest
Warning

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

Go to latest
Published: May 13, 2023 License: ISC Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTemplate = `` /* 165-byte string literal not displayed */

DefaultTemplate is used when no template is given.

Variables

View Source
var NewLine = []byte("\n")

NewLine contains ['\n']

Functions

func RegisterStacktracer

func RegisterStacktracer(tracer StacktraceFormatter)

RegisterStacktracer adds a StacktraceFormatter to a thé list.

Types

type Entry

type Entry struct {
	Timestamp      *time.Time `djson:"timestamp,@timestamp,time,date,ts"`
	RawTimestamp   string     `djson:"timestamp,@timestamp,time,date,ts"`
	FloatTimestamp float64    `djson:"timestamp,@timestamp,time,date,ts"`
	Severity       string     `djson:"severity,level,log.level"`
	Message        string     `djson:"message,msg,text"`

	Name string `djson:"app,name,service.name"`
}

Entry represents a structured logline to be formatted.

type Formatter

type Formatter struct {
	Colorize       bool
	ShowFields     bool
	MaxFieldLength int
	ShowPrefix     bool
	ShowSuffix     bool
	IncludeFields  string
	ExcludeFields  []string
	ObjFields      []string
	// contains filtered or unexported fields
}

Formatter is the system that outputs a sturctured log entry as a nice readable line using a small go template (which could be given via the cli)

func NewFormatter

func NewFormatter(w io.Writer, fmt string) (*Formatter, error)

NewFormatter compiles the given fmt as a go template and returns a Formatter

func (*Formatter) Format

func (f *Formatter) Format(entry *Entry, raw json.RawMessage, prefix, suffix []byte) error

Format takes a structured log entry and formats it according the template.

type StacktraceFormatter

type StacktraceFormatter interface {
	Detect(json map[string]interface{}) bool
	Format(json map[string]interface{}) string
}

StacktraceFormatter interfaces with the Formatter to format a possible stacktrace in a JSON log line. The Detect method returns true if it's compatible.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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