Documentation
¶
Index ¶
- Constants
- Variables
- func TransformType[T any](trans func(val T) T) func(any) any
- type CutCollectSpec
- type CutOpt
- type LogEntry
- func (e LogEntry) AsFloat(name string) (float64, bool)
- func (e LogEntry) AsInt(name string) (int64, bool)
- func (e LogEntry) AsString(name string) (string, bool)
- func (e LogEntry) AsTime(name string, format ...string) (time.Time, bool)
- func (e LogEntry) AsUint(name string) (uint64, bool)
- func (e LogEntry) Format(format string, fields ...string) string
- func (e LogEntry) HasField(name string) bool
- func (e LogEntry) HasTag(tag string) bool
- func (e LogEntry) Tag(tag string)
- type ReassignSpec
- type SourceField
- type SubjectField
- type TargetField
- type TransformSpec
Constants ¶
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 ¶
var (
ErrNotACutString = errors.New("field is not a cuttable string")
)
Functions ¶
func TransformType ¶
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 ¶
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 ¶
CutCollector defines a function that will be used to stitch Cut fields into the message.
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 ¶
LogEntry is a single entry in a log, with potentially many fields.
func Cut ¶
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 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.
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.