event

package
v0.0.0-...-660a5ed Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2022 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Default_Event_Prefix = string("log")
	Default_Event_Level  = Level_info
)

Default values for Event fields.

Variables

View Source
var (
	Level_name = map[int32]string{
		0: "trace",
		1: "debug",
		2: "info",
		3: "warn",
		4: "error",
		5: "fatal",
		9: "panic",
	}
	Level_value = map[string]int32{
		"trace": 0,
		"debug": 1,
		"info":  2,
		"warn":  3,
		"error": 4,
		"fatal": 5,
		"panic": 9,
	}
)

Enum value maps for Level.

View Source
var File_proto_event_proto protoreflect.FileDescriptor

Functions

func Encode

func Encode(e *Event) (b []byte, err error)

Encode function will take in a protobuf Event, and convert it to a slice of bytes, returning this and an error if any.

Types

type Event

type Event struct {
	Time   *timestamppb.Timestamp `protobuf:"bytes,1,opt,name=time" json:"time,omitempty"`
	Prefix *string                `protobuf:"bytes,2,opt,name=prefix,def=log" json:"prefix,omitempty"`
	Sub    *string                `protobuf:"bytes,3,opt,name=sub" json:"sub,omitempty"`
	Level  *Level                 `protobuf:"varint,4,opt,name=level,enum=event.Level,def=2" json:"level,omitempty"`
	Msg    *string                `protobuf:"bytes,5,req,name=msg" json:"msg,omitempty"`
	Meta   *structpb.Struct       `protobuf:"bytes,6,opt,name=meta" json:"meta,omitempty"`
	// contains filtered or unexported fields
}

func Decode

func Decode(b []byte) (*Event, error)

Decode function will take in a slice of bytes and convert it to an Event protobuf, returning this and an error if any.

func (*Event) Decode

func (e *Event) Decode(b []byte)

Decode method is similar to Event.Unmarshal, but it does not return any errors

func (*Event) Descriptor deprecated

func (*Event) Descriptor() ([]byte, []int)

Deprecated: Use Event.ProtoReflect.Descriptor instead.

func (*Event) Encode

func (e *Event) Encode() []byte

Encode method is similar to Event.Marshal(), but it does not return any errors

func (*Event) GetLevel

func (x *Event) GetLevel() Level

func (*Event) GetMeta

func (x *Event) GetMeta() *structpb.Struct

func (*Event) GetMsg

func (x *Event) GetMsg() string

func (*Event) GetPrefix

func (x *Event) GetPrefix() string

func (*Event) GetSub

func (x *Event) GetSub() string

func (*Event) GetTime

func (x *Event) GetTime() *timestamppb.Timestamp

func (*Event) Marshal

func (e *Event) Marshal() ([]byte, error)

Marshal method will convert the protobuf Event into a slice of bytes, also returning potential errors in the convertion

func (*Event) ProtoMessage

func (*Event) ProtoMessage()

func (*Event) ProtoReflect

func (x *Event) ProtoReflect() protoreflect.Message

func (*Event) Reset

func (x *Event) Reset()

func (*Event) String

func (x *Event) String() string

func (*Event) Unmarshal

func (e *Event) Unmarshal(b []byte) error

Unmarshal method will convert the input slice of bytes as a protobuf Event, stored in the method receiver. Returns an error if any.

type EventBuilder

type EventBuilder struct {
	BTime     *time.Time
	BPrefix   *string
	BSub      *string
	BLevel    *Level
	BMsg      string
	BMetadata *map[string]interface{}
}

EventBuilder struct describes the elements in an Events's builder, which will be the target of different changes until its `Build()` method is called -- returning then a pointer to an Events object

func New

func New() *EventBuilder

New function is the initializer of an EventBuilder. From this call, further EventBuilder methods can be chained since they all return pointers to the same

This builder returns an EventBuilder struct with initialized pointers to its elements, which is exactly the same implementation as the protobuf message, without protobuf-specific data types

func (*EventBuilder) Build

func (b *EventBuilder) Build() *Event

Build method will create a new timestamp, review all elements in the `EventBuilder`, apply any defaults to non-defined elements, and return a pointer to an Event

func (*EventBuilder) CallStack

func (b *EventBuilder) CallStack(all bool) *EventBuilder

CallStack method will grab the current call stack, and add it as a "callstack" object in the EventBuilder's metadata.

func (*EventBuilder) Level

func (b *EventBuilder) Level(l Level) *EventBuilder

Level method will set the level element in the EventBuilder with LogLevel l, and return the builder

func (*EventBuilder) Message

func (b *EventBuilder) Message(m string) *EventBuilder

Message method will set the message element in the EventBuilder with string m, and return the builder

func (*EventBuilder) Metadata

func (b *EventBuilder) Metadata(m map[string]interface{}) *EventBuilder

Metadata method will set (or add) the metadata element in the EventBuilder with map m, and return the builder

func (*EventBuilder) Prefix

func (b *EventBuilder) Prefix(p string) *EventBuilder

Prefix method will set the prefix element in the EventBuilder with string p, and return the builder

func (*EventBuilder) Sub

func (b *EventBuilder) Sub(s string) *EventBuilder

Sub method will set the sub-prefix element in the EventBuilder with string s, and return the builder

type Field

type Field map[string]interface{}

Field type is a generic type to build Event Metadata

func (Field) AsMap

func (f Field) AsMap() map[string]interface{}

AsMap method returns the Field in it's (raw) string-interface{} map format

func (Field) Encode

func (f Field) Encode() *structpb.Struct

Encode method is similar to Field.ToStructPB(), but it does not return any errors.

func (Field) ToStructPB

func (f Field) ToStructPB() (*structpb.Struct, error)

ToStructPB method will convert the metadata in the protobuf Event as a pointer to a structpb.Struct, returning this and an error if any.

The metadata (a map[string]interface{}) is converted to JSON (bytes), and this data is unmarshalled into a *structpb.Struct object.

type Level

type Level int32
const (
	Level_trace Level = 0
	Level_debug Level = 1
	Level_info  Level = 2
	Level_warn  Level = 3
	Level_error Level = 4
	Level_fatal Level = 5
	Level_panic Level = 9
)

func (Level) Descriptor

func (Level) Descriptor() protoreflect.EnumDescriptor

func (Level) Enum

func (x Level) Enum() *Level

func (Level) EnumDescriptor deprecated

func (Level) EnumDescriptor() ([]byte, []int)

Deprecated: Use Level.Descriptor instead.

func (Level) Int

func (l Level) Int() int32

Int method is used to grab the int32 enum value of the Level in the Event

This value may be used for log-level-filtering

func (Level) Number

func (x Level) Number() protoreflect.EnumNumber

func (Level) String

func (x Level) String() string

func (Level) Type

func (Level) Type() protoreflect.EnumType

func (*Level) UnmarshalJSON deprecated

func (x *Level) UnmarshalJSON(b []byte) error

Deprecated: Do not use.

Jump to

Keyboard shortcuts

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