log

package
v0.50.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFieldSet

func GetFieldSet[T FieldSet](l *Log, fieldSet T) (T, error)

GetFieldSet returns the read FieldSet associated with the log. It returns an error when the FieldSet wasn't found on the log.

func MustGetFieldSet

func MustGetFieldSet[T FieldSet](l *Log, fieldSet T) T

MustGetFieldSet returns the read FieldSet associated with the log. It will go panic when the FieldSet was not found on the log.

Types

type CommonFieldSet

type CommonFieldSet struct {
	// Timestamp is the timestamp of the log happens.
	Timestamp time.Time
	// Severity represents the log severity.
	Severity enum.Severity
	// DisplayID is an unique identifier given from a log.
	// This is only used for showing and it may be same as the ID.
	DisplayID string
}

CommonFieldSet is an abstract FieldSet struct type to get fields commonly defined in logs.

func (*CommonFieldSet) Kind

func (c *CommonFieldSet) Kind() string

Kind implements FieldSet.

type FieldSet

type FieldSet interface {
	// FieldSetKind identifies the set of fields. It must be same if the result type has same fields.
	Kind() string
}

FieldSet represents set of log fields read from a log. FieldSet implementations defines how to read these actual fields from a log for parsers to read without using explicit path of field.

type FieldSetReader

type FieldSetReader interface {
	// Read attempts to read the log fields into its field.
	Read(reader *structured.NodeReader) (FieldSet, error)

	// FieldSetKind identifies the set of fields. It must be same if the result type has same fields.
	FieldSetKind() string
}

type Log

type Log struct {
	*structured.NodeReader

	ID      string
	LogType enum.LogType
	// contains filtered or unexported fields
}

Log represents a log handled in KHI. It provides direct access to its fields and abstracted cached access via FieldSet interface.

func NewLog

func NewLog(reader *structured.NodeReader) *Log

NewLog returns a log instance from NodeReader instance.

func NewLogFromYAMLString

func NewLogFromYAMLString(yaml string) (*Log, error)

NewLogFromYAMLString instanciate a new Log from the given YAML string.

func NewLogWithFieldSetsForTest

func NewLogWithFieldSetsForTest(fieldSets ...FieldSet) *Log

NewLogWithFieldSetsForTest generate an empty Log with given FieldSet. This is for testing purpose to instanciate a log already parsed.

func (*Log) SetFieldSetReader

func (l *Log) SetFieldSetReader(reader FieldSetReader) error

SetFieldSetReader reads set of fields with the FieldSetReader and keep it in the log.

type MainMessageFieldSet

type MainMessageFieldSet struct {
	MainMessage string
}

MainMessageFieldSet is an abstract FieldSet struct type to get the main message of its log. This would be read from `textPayload`, `protoPayload` or `jsonPayload` when it is read from Cloud Logging.

func (*MainMessageFieldSet) HasKLogField

func (m *MainMessageFieldSet) HasKLogField(fieldName string) bool

HasKLogField parses the main message as the klog format and returns if the field exists.

func (*MainMessageFieldSet) KLogField

func (m *MainMessageFieldSet) KLogField(fieldName string) (string, error)

KLogField parses the main message as the klog format and returns the field value.

func (*MainMessageFieldSet) KLogSeverity

func (m *MainMessageFieldSet) KLogSeverity() enum.Severity

KLogSeverity reads the severity field from KLog formatted message.

func (*MainMessageFieldSet) Kind

func (d *MainMessageFieldSet) Kind() string

Kind implements FieldSet.

Jump to

Keyboard shortcuts

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