entries

package
v0.0.0-...-31ca664 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StandardMessageField   = "@message"   // StandardMessageField is an unstructured logging payload
	StandardTimestampField = "@timestamp" // StandardTimestampField represents the date and time that the LogEntry was emitted
	StandardLevelField     = "@level"     // StandardLevelField specifies the logging level used
	StandardModuleField    = "@module"    // StandardModuleField references a source system specific component hierarchy
	StandardCallerField    = "@caller"    // StandardCallerField specifies the caller of the routine emitting this log entry
	StandardTagField       = "@tag"       // StandardTagField contains classifiers for a LogEntry that may be unrelated to the payload, but relate to the context in which it was emitted
)

Variables

View Source
var (
	ErrNotACutString = errors.New("field is not a cuttable string")
)

Functions

func TransformType

func TransformType[T any](trans func(val T) T) func(any) any

TransformType will create a transform function that first asserts that the field type matches the expected type for the given transform function. If the types don't match, then the transform function will not be called.

Types

type CutCollectSpec

type CutCollectSpec map[int]func(entry LogEntry, value string)

CutCollectSpec will specify the destination for a field as the output of Cut. Any unmapped fields will be ignored.

func NewCutCollectSpec

func NewCutCollectSpec() CutCollectSpec

func (CutCollectSpec) Collector

func (c CutCollectSpec) Collector() func(entry LogEntry, fields []string) (LogEntry, string)

func (CutCollectSpec) Map

func (c CutCollectSpec) Map(field string, idx int) CutCollectSpec

Map will copy the Cut field at idx to field. Map calls can override each other by specifying the same field and/or idx multiple times. Map can accept negative indexes to refer to fields at the end of a line of text, starting with -1. Any value set by a mapping may be overridden by another mapping. Ensure that all calls to Map reference any given field only once.

type CutOpt

type CutOpt func(opts *cutOpts)

CutOpt represents a functional option for Cut.

func CutCollector

func CutCollector(fn func(entry LogEntry, fields []string) (LogEntry, string)) CutOpt

CutCollector defines a function that will be used to stitch Cut fields into the message.

func CutDelim

func CutDelim(delim string) CutOpt

CutDelim specifies the delimiter to use to split the field in Cut.

func CutField

func CutField(field string) CutOpt

CutField specifies the field to use as the basis for Cut.

func RemoveSource

func RemoveSource() CutOpt

RemoveSource specifies that the source field transformed by Cut should be removed after successful processing.

func RetainBlankFields

func RetainBlankFields() CutOpt

type LogEntry

type LogEntry map[string]any

LogEntry is a single entry in a log, with potentially many fields.

func Cut

func Cut(entry LogEntry, opt ...CutOpt) (LogEntry, error)

Cut allows programmatically parsing out a log message into more atomic parts by splitting on one or more instances of delimiter, much like the unix cut command. Cut assumes it should be parsing the StandardMessageField with a space character unless overridden. The source field must be a string for Cut to operate as intended.

func FromString

func FromString(msg string) LogEntry

func Reassign

func Reassign(entry LogEntry, spec ReassignSpec) LogEntry

Reassign runs a ReassignSpec against a LogEntry to move one or more fields.

func Transform

func Transform(entry LogEntry, spec TransformSpec) LogEntry

Transform transforms field values according to the given TransformSpec.

func (LogEntry) AsFloat

func (e LogEntry) AsFloat(name string) (float64, bool)

func (LogEntry) AsInt

func (e LogEntry) AsInt(name string) (int64, bool)

func (LogEntry) AsString

func (e LogEntry) AsString(name string) (string, bool)

func (LogEntry) AsTime

func (e LogEntry) AsTime(name string, format ...string) (time.Time, bool)

func (LogEntry) AsUint

func (e LogEntry) AsUint(name string) (uint64, bool)

func (LogEntry) Format

func (e LogEntry) Format(format string, fields ...string) string

func (LogEntry) HasField

func (e LogEntry) HasField(name string) bool

func (LogEntry) HasTag

func (e LogEntry) HasTag(tag string) bool

HasTag determines if this LogEntry has a tag matching the parameter. Values will be compared ignoring case.

func (LogEntry) Tag

func (e LogEntry) Tag(tag string)

Tag sets a tag on this LogEntry. A Tag is intended to classify the LogEntry in some way, presumably for filtering later. If a tag has already been set, then the parameter will be appended with a period separator.

type ReassignSpec

type ReassignSpec map[SourceField]TargetField

ReassignSpec contains mapping details for renaming a field from SourceField to TargetField.

func NewReassignSpec

func NewReassignSpec() ReassignSpec

func (ReassignSpec) Move

func (s ReassignSpec) Move(source SourceField, target TargetField) ReassignSpec

Move sets a value in the ReassignSpec that moves a field's value.

type SourceField

type SourceField string

type SubjectField

type SubjectField string

type TargetField

type TargetField string

type TransformSpec

type TransformSpec map[SubjectField]transFunc

TransformSpec contains the transform functions for any given field in a LogEntry. If the field is not found or is nil, then the transform function will not be executed.

func NewTransformSpec

func NewTransformSpec() TransformSpec

func (TransformSpec) Transform

func (s TransformSpec) Transform(field SubjectField, trans transFunc) TransformSpec

Transform will add a field transform. Adding a transform for a field where one is already assigned will append the given transform function to the existing one.

Jump to

Keyboard shortcuts

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