plogd

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextProg

func ContextProg(ctx context.Context) string

ContextProg returns the prog stored in ctx, if any. Otherwise empty string.

func ContextWithProg

func ContextWithProg(ctx context.Context, prog string) context.Context

ContextWithProg creates a new context with prog stored.

Types

type LogMessage

type LogMessage struct {
	Timestamp time.Time   `json:"@timestamp"`
	Prog      string      `json:"prog"`
	Type      string      `json:"type"`
	Message   interface{} `json:"message"`
	// Use a pointer to work around MarshalJSON encoding Time even if zero value
	StartTimestamp *time.Time `json:"start_timestamp,omitempty"`
	Host           string     `json:"host,omitempty"`

	// Extra fields added by filters.
	KV map[string]interface{} `json:"-"`
}

LogMessage is the type used for when a message is contructed and is ready to be sent off. Struct order matters for Marshaling, keep Timestamp first.

func (*LogMessage) MarshalJSON

func (msg *LogMessage) MarshalJSON() ([]byte, error)

MarshalJSON creates a proper JSON type, incorporating the KV map as needed.

func (*LogMessage) ToMap

func (msg *LogMessage) ToMap() map[string]interface{}

ToMap creates a map[string]interface{} representation of the message. This function will modify msg.KV and return it, to save the need of copying it.

type NewOutputFunc

type NewOutputFunc func(url.Values, string) (OutputWriter, error)

NewOutputFunc is the signature that the function NewOutput should have in output plugins.

type OutputWriter

type OutputWriter interface {
	WriteMessage(ctx context.Context, message LogMessage)
	Close() error
}

OutputWriter is the interface used to write log messages.

func NewQueuedWriter

func NewQueuedWriter(w OutputWriter) OutputWriter

NewQueuedWriter wraps w such that w.WriteMessage is called asynchronously from a single goroutine, and is thus never called in parallell. If additional messages arrives to the QueuedWriter while that happens, they'll be queued up and delivered one at a time. w.Close will also be called from the same goroutine during shutdown after all messages have ben flushed. The Close call has a 5 second timeout after it will return with an error.

Jump to

Keyboard shortcuts

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