hook

package
v0.54.1 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: BSD-3-Clause Imports: 21 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ChunkSize = 8154
)

Used to control GELF chunking. Should be less than (MTU - len(UDP header)).

TODO: generate dynamically using Path MTU Discovery?

Variables

View Source
var BufSize uint = 16384

Set graylog.BufSize = <value> _before_ calling NewHook Once the buffer is full, logging will start blocking, waiting for slots to be available in the queue.

Functions

func DropPolicy

func DropPolicy(msg *Message, ch chan *Message)

DropPolicy will drop the message if the channel is full

Types

type CompressType

type CompressType int

What compression type the writer should use when sending messages to the graylog2 server

const (
	CompressGzip CompressType = iota
	CompressZlib
)

type Config

type Config struct {
	Addr           string
	Protocol       string
	Hostname       string
	Facility       string
	TLSConfig      *tls.Config
	Merge          func(...map[string]interface{}) map[string]interface{}
	ThrottlePolicy *ThrottlePolicyConfig
}

Config is the required configuration for creating a Graylog hook

type DefaultThrottlePolicy

type DefaultThrottlePolicy struct {
	// contains filtered or unexported fields
}

func (*DefaultThrottlePolicy) Flush

func (d *DefaultThrottlePolicy) Flush()

func (*DefaultThrottlePolicy) HandleTrailingMessage

func (d *DefaultThrottlePolicy) HandleTrailingMessage(m Message)

func (*DefaultThrottlePolicy) Init

func (d *DefaultThrottlePolicy) Init(hook *Hook)

func (*DefaultThrottlePolicy) PendingTrailingMessages

func (d *DefaultThrottlePolicy) PendingTrailingMessages() bool

type FireMessageFunc

type FireMessageFunc func(msg Message) error

type Hook

type Hook struct {
	Facility string
	Hostname string
	// Extra fields to send to Graylog for each log entry.
	Extra map[string]interface{}
	// Minimum logging level to send to Graylog.
	// Must be set before adding to logrus logger.
	// Default is logrus.InfoLevel.
	Threshold logrus.Level

	Pid int
	// contains filtered or unexported fields
}

Hook to send logs to a logging service compatible with the Graylog API and the GELF format.

func NewHook

func NewHook(ctx context.Context, cfg *Config, extra map[string]interface{}) (*Hook, error)

NewHook creates a hook to be added to an instance of logger.

func (*Hook) Fire

func (hook *Hook) Fire(entry *logrus.Entry) error

Fire is called when a log event is fired. We assume the entry will be altered by another hook, otherwise we might logging something wrong to Graylog

func (*Hook) FireMessage

func (hook *Hook) FireMessage(msg Message) error

func (*Hook) Flush

func (hook *Hook) Flush()

func (*Hook) IsThrottled

func (hook *Hook) IsThrottled() bool

func (*Hook) Levels

func (hook *Hook) Levels() []logrus.Level

Levels returns the available logging levels.

func (*Hook) Stop

func (hook *Hook) Stop()

type MergeFields

type MergeFields func(...map[string]interface{}) map[string]interface{}

MergeFields defines a function to merge fields. It used for example to define your own field convientions to match with your graylog service.

type Message

type Message struct {
	Version  string                 `json:"version"`
	Host     string                 `json:"host"`
	Short    string                 `json:"short_message"`
	Full     string                 `json:"full_message,omitempty"`
	Time     float64                `json:"timestamp"`
	Level    int32                  `json:"level"`
	Pid      int                    `json:"_pid,omitempty"`
	Facility string                 `json:"_facility,omitempty"` // optional, deprecated, send as additional field
	File     string                 `json:"_file,omitempty"`     // optional, deprecated, send as additional field
	Line     int                    `json:"_line,omitempty"`     // optional, deprecated, send as additional field
	Prefix   string                 `json:"_prefix,omitempty"`
	Extra    map[string]interface{} `json:"-"`
}

Message represents the contents of the GELF message. It is gzipped before sending.

func (*Message) MarshalJSON

func (m *Message) MarshalJSON() ([]byte, error)

func (*Message) UnmarshalJSON

func (m *Message) UnmarshalJSON(data []byte) error

type Priority

type Priority int
const (

	// From /usr/include/sys/syslog.h.
	// These are the same on Linux, BSD, and OS X.
	LOG_EMERG Priority = iota
	LOG_ALERT
	LOG_CRIT
	LOG_ERR
	LOG_WARNING
	LOG_NOTICE
	LOG_INFO
	LOG_DEBUG
)

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

func (*Reader) Addr

func (r *Reader) Addr() string

func (*Reader) Close

func (r *Reader) Close() error

func (*Reader) Read

func (r *Reader) Read(p []byte) (int, error)

FIXME: this will discard data if p isn't big enough to hold the full message.

func (*Reader) ReadMessage

func (r *Reader) ReadMessage() (*Message, error)

type Stack

type Stack struct {
	// contains filtered or unexported fields
}

Stack is a basic LIFO stack that resizes as needed.

func NewStack

func NewStack(cap int) *Stack

NewStack returns a new stack.

func (*Stack) Empty

func (q *Stack) Empty() bool

func (*Stack) Pop

func (q *Stack) Pop() (Message, bool)

Pop removes and returns a node from the queue in first to last order.

func (*Stack) Push

func (q *Stack) Push(n Message)

Push adds a node to the queue.

func (*Stack) Ready

func (q *Stack) Ready() bool

type TCPWriter

type TCPWriter struct {
	Hostname string
	Facility string
	// contains filtered or unexported fields
}

TCPWriter implements io.Writer and is used to send both discret messages to a graylog2 server, or data from a stream-oriented interface (like the functions in log).

func NewTCPWriter

func NewTCPWriter(addr string, tlsCfg *tls.Config) (*TCPWriter, error)

NewTCPWriter returns a new TCP GELF Writer. This writer can be used to send the output of the standard Go log functions to a central GELF server by passing it to log.SetOutput()

func (*TCPWriter) Write

func (w *TCPWriter) Write(p []byte) (int, error)

Write writes a given data, converts it to a GELF message and writes it with the current TCP connection

func (*TCPWriter) WriteMessage

func (w *TCPWriter) WriteMessage(m *Message) error

WriteMessage writes a GELF message with current TCP connection

type ThrottlePolicy

type ThrottlePolicy interface {
	Init(hook *Hook)
	HandleTrailingMessage(m Message)
	PendingTrailingMessages() bool
	Flush()
}

func NewDefaultThrottlePolicy

func NewDefaultThrottlePolicy() ThrottlePolicy

type ThrottlePolicyConfig

type ThrottlePolicyConfig struct {
	Amount int
	Period time.Duration
	Policy ThrottlePolicy
}

type UDPWriter

type UDPWriter struct {
	Facility         string // defaults to current process name
	CompressionLevel int    // one of the consts from compress/flate
	CompressionType  CompressType
	// contains filtered or unexported fields
}

UDPWriter implements io.Writer and is used to send both discrete messages to a graylog2 server, or data from a stream-oriented interface (like the functions in log).

func NewUDPWriter

func NewUDPWriter(addr string) (*UDPWriter, error)

NewUDPWriter returns a new GELF Writer. This writer can be used to send the output of the standard Go log functions to a central GELF server by passing it to log.SetOutput()

func (*UDPWriter) Write

func (w *UDPWriter) Write(p []byte) (n int, err error)

Write encodes the given string in a GELF message and sends it to the server specified in New().

func (*UDPWriter) WriteMessage

func (w *UDPWriter) WriteMessage(m *Message) (err error)

WriteMessage sends the specified message to the GELF server specified in the call to New(). It assumes all the fields are filled out appropriately. In general, clients will want to use Write, rather than WriteMessage.

type Writer

type Writer interface {
	io.Writer
	WriteMessage(*Message) error
}

Jump to

Keyboard shortcuts

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