entry

package
v0.68.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: Apache-2.0 Imports: 5 Imported by: 23

Documentation

Index

Constants

View Source
const (
	AttributesPrefix = "attributes"
	ResourcePrefix   = "resource"
	BodyPrefix       = "body"
)
View Source
const (
	// Begin is the beginning state of a field split
	Begin splitState = iota
	// InBracket is the state of a field split inside a bracket
	InBracket
	// InQuote is the state of a field split inside a quote
	InQuote
	// OutQuote is the state of a field split outside a quote
	OutQuote
	// OutBracket is the state of a field split outside a bracket
	OutBracket
	// InUnbracketedToken is the state field split on any token outside brackets
	InUnbracketedToken
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AttributeField

type AttributeField struct {
	Keys []string
}

AttributeField is the path to an entry attribute

func (AttributeField) Child

func (f AttributeField) Child(key string) AttributeField

Child returns a child of the current field using the given key.

func (AttributeField) Delete

func (f AttributeField) Delete(entry *Entry) (interface{}, bool)

Delete removes a value from an entry's attributes using the field. It will return the deleted value and whether the field existed.

func (AttributeField) Get

func (f AttributeField) Get(entry *Entry) (interface{}, bool)

Get will return the attribute value and a boolean indicating if it exists

func (AttributeField) Merge

func (f AttributeField) Merge(entry *Entry, mapValues map[string]interface{})

Merge will attempt to merge the contents of a map into an entry's attributes. It will overwrite any intermediate values as necessary.

func (AttributeField) Parent

func (f AttributeField) Parent() AttributeField

Parent returns the parent of the current field. In the case that the attribute field points to the root node, it is a no-op.

func (AttributeField) Set

func (f AttributeField) Set(entry *Entry, value interface{}) error

Set will set a value on an entry's attributes using the field. If a key already exists, it will be overwritten.

func (AttributeField) String

func (f AttributeField) String() string

String returns the string representation of this field.

func (*AttributeField) UnmarshalJSON

func (f *AttributeField) UnmarshalJSON(raw []byte) error

UnmarshalJSON will attempt to unmarshal the field from JSON.

func (*AttributeField) UnmarshalText added in v0.59.0

func (f *AttributeField) UnmarshalText(text []byte) error

UnmarshalText will unmarshal a field from text

func (*AttributeField) UnmarshalYAML

func (f *AttributeField) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML will attempt to unmarshal a field from YAML.

type BodyField

type BodyField struct {
	Keys []string
}

BodyField is a field found on an entry body.

func (BodyField) Child

func (f BodyField) Child(key string) BodyField

Child returns a child of the current field using the given key.

func (BodyField) Delete

func (f BodyField) Delete(entry *Entry) (interface{}, bool)

Delete removes a value from an entry's body using the field. It will return the deleted value and whether the field existed.

func (BodyField) Get

func (f BodyField) Get(entry *Entry) (interface{}, bool)

Get will retrieve a value from an entry's body using the field. It will return the value and whether the field existed.

func (BodyField) Merge

func (f BodyField) Merge(entry *Entry, mapValues map[string]interface{})

Merge will attempt to merge the contents of a map into an entry's body. It will overwrite any intermediate values as necessary.

func (BodyField) Parent

func (f BodyField) Parent() BodyField

Parent returns the parent of the current field. In the case that the body field points to the root node, it is a no-op.

func (BodyField) Set

func (f BodyField) Set(entry *Entry, value interface{}) error

Set will set a value on an entry's body using the field. If a key already exists, it will be overwritten.

func (BodyField) String

func (f BodyField) String() string

String returns the string representation of this field.

func (*BodyField) UnmarshalJSON

func (f *BodyField) UnmarshalJSON(raw []byte) error

UnmarshalJSON will attempt to unmarshal the field from JSON.

func (*BodyField) UnmarshalText added in v0.59.0

func (f *BodyField) UnmarshalText(text []byte) error

UnmarshalText will unmarshal a field from text

func (*BodyField) UnmarshalYAML

func (f *BodyField) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML will attempt to unmarshal a field from YAML.

type Entry

type Entry struct {
	ObservedTimestamp time.Time              `json:"observed_timestamp"      yaml:"observed_timestamp"`
	Timestamp         time.Time              `json:"timestamp"               yaml:"timestamp"`
	Body              interface{}            `json:"body"                    yaml:"body"`
	Attributes        map[string]interface{} `json:"attributes,omitempty"    yaml:"attributes,omitempty"`
	Resource          map[string]interface{} `json:"resource,omitempty"      yaml:"resource,omitempty"`
	SeverityText      string                 `json:"severity_text,omitempty" yaml:"severity_text,omitempty"`
	SpanID            []byte                 `json:"span_id,omitempty"       yaml:"span_id,omitempty"`
	TraceID           []byte                 `json:"trace_id,omitempty"      yaml:"trace_id,omitempty"`
	TraceFlags        []byte                 `json:"trace_flags,omitempty"   yaml:"trace_flags,omitempty"`
	Severity          Severity               `json:"severity"                yaml:"severity"`
	ScopeName         string                 `json:"scope_name"              yaml:"scope_name"`
}

Entry is a flexible representation of log data associated with a timestamp.

func New

func New() *Entry

New will create a new log entry with current timestamp and an empty body.

func (*Entry) AddAttribute

func (entry *Entry) AddAttribute(key, value string)

AddAttribute will add a key/value pair to the entry's attributes.

func (*Entry) AddResourceKey

func (entry *Entry) AddResourceKey(key, value string)

AddResourceKey wil add a key/value pair to the entry's resource.

func (*Entry) Copy

func (entry *Entry) Copy() *Entry

Copy will return a deep copy of the entry.

func (*Entry) Delete

func (entry *Entry) Delete(field FieldInterface) (interface{}, bool)

Delete will delete a field from the entry.

func (*Entry) Get

func (entry *Entry) Get(field FieldInterface) (interface{}, bool)

Get will return the value of a field on the entry, including a boolean indicating if the field exists.

func (*Entry) Read

func (entry *Entry) Read(field FieldInterface, dest interface{}) error

Read will read the value of a field into a designated interface.

func (*Entry) Set

func (entry *Entry) Set(field FieldInterface, val interface{}) error

Set will set the value of a field on the entry.

type Field

type Field struct {
	FieldInterface
}

Field represents a potential field on an entry. It is used to get, set, and delete values at this field. It is deserialized from JSON dot notation.

func NewAttributeField

func NewAttributeField(keys ...string) Field

NewAttributeField will creat a new attribute field from a key

func NewBodyField

func NewBodyField(keys ...string) Field

NewBodyField creates a new field from an ordered array of keys.

func NewField

func NewField(s string) (Field, error)

func NewNilField

func NewNilField() Field

NewNilField will create a new nil field

func NewResourceField

func NewResourceField(keys ...string) Field

NewResourceField will creat a new resource field from a key

func (*Field) UnmarshalJSON

func (f *Field) UnmarshalJSON(raw []byte) error

UnmarshalJSON will unmarshal a field from JSON

func (*Field) UnmarshalText added in v0.59.0

func (f *Field) UnmarshalText(text []byte) error

UnmarshalText will unmarshal a field from text

func (*Field) UnmarshalYAML

func (f *Field) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML will unmarshal a field from YAML

type FieldInterface

type FieldInterface interface {
	Get(*Entry) (interface{}, bool)
	Set(entry *Entry, value interface{}) error
	Delete(entry *Entry) (interface{}, bool)
	String() string
}

FieldInterface is a field on an entry.

type NilField

type NilField struct{}

NilField is a struct that implements Field, but does nothing for all its operations. It is useful as a default no-op field to avoid nil checks.

func (NilField) Delete

func (l NilField) Delete(entry *Entry) (interface{}, bool)

Delete will do nothing and return no error

func (NilField) Get

func (l NilField) Get(entry *Entry) (interface{}, bool)

Get will return always return nil

func (NilField) Set

func (l NilField) Set(entry *Entry, val interface{}) error

Set will do nothing and return no error

func (NilField) String

func (l NilField) String() string

type ResourceField

type ResourceField struct {
	Keys []string
}

ResourceField is the path to an entry resource

func (ResourceField) Child

func (f ResourceField) Child(key string) ResourceField

Child returns a child of the current field using the given key.

func (ResourceField) Delete

func (f ResourceField) Delete(entry *Entry) (interface{}, bool)

Delete removes a value from an entry's resource using the field. It will return the deleted value and whether the field existed.

func (ResourceField) Get

func (f ResourceField) Get(entry *Entry) (interface{}, bool)

Get will return the resource value and a boolean indicating if it exists

func (ResourceField) Merge

func (f ResourceField) Merge(entry *Entry, mapValues map[string]interface{})

Merge will attempt to merge the contents of a map into an entry's resource. It will overwrite any intermediate values as necessary.

func (ResourceField) Parent

func (f ResourceField) Parent() ResourceField

Parent returns the parent of the current field. In the case that the resource field points to the root node, it is a no-op.

func (ResourceField) Set

func (f ResourceField) Set(entry *Entry, value interface{}) error

Set will set a value on an entry's resource using the field. If a key already exists, it will be overwritten.

func (ResourceField) String

func (f ResourceField) String() string

String returns the string representation of this field.

func (*ResourceField) UnmarshalJSON

func (f *ResourceField) UnmarshalJSON(raw []byte) error

UnmarshalJSON will attempt to unmarshal the field from JSON.

func (*ResourceField) UnmarshalText added in v0.59.0

func (f *ResourceField) UnmarshalText(text []byte) error

UnmarshalText will unmarshal a field from text

func (*ResourceField) UnmarshalYAML

func (f *ResourceField) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML will attempt to unmarshal a field from YAML.

type RootableField added in v0.61.0

type RootableField struct {
	Field
}

RootableField is a Field that may refer directly to "attributes" or "resource"

func (*RootableField) UnmarshalJSON added in v0.61.0

func (r *RootableField) UnmarshalJSON(raw []byte) error

UnmarshalJSON will unmarshal a field from JSON

func (*RootableField) UnmarshalText added in v0.61.0

func (r *RootableField) UnmarshalText(text []byte) error

UnmarshalText will unmarshal a field from text

func (*RootableField) UnmarshalYAML added in v0.61.0

func (r *RootableField) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML will unmarshal a field from YAML

type Severity

type Severity int

Severity indicates the seriousness of a log entry

const (
	// Default indicates an unknown severity
	Default Severity = iota

	// A fine-grained debugging event. Typically disabled in default configurations.
	Trace
	Trace2
	Trace3
	Trace4

	// A debugging event.
	Debug
	Debug2
	Debug3
	Debug4

	// An informational event. Indicates that an event happened.
	Info
	Info2
	Info3
	Info4

	// A warning event. Not an error but is likely more important than an informational event.
	Warn
	Warn2
	Warn3
	Warn4

	// An error event. Something went wrong.
	Error
	Error2
	Error3
	Error4

	// An error event. Something went wrong.
	Fatal
	Fatal2
	Fatal3
	Fatal4
)

func (Severity) String

func (s Severity) String() string

ToString converts a severity to a string

Jump to

Keyboard shortcuts

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