sockrus

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2023 License: GPL-3.0 Imports: 4 Imported by: 0

README

Socket hook for logrus

Use this hook to send the logs over UDP, TCP or Unix socket.

Output format is JSON, formatted for Logstash/ElasticSearch.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSockrus

func NewSockrus(config Config) (*logrus.Logger, *logrus.Entry)

NewSockrus is a wrapper for initialization of logrus with sockrus hook. It returns new instance of logrus.Logger and logrus.Entry. All errors are fatal.

Types

type Config

type Config struct {
	Hostname       string       // Hostname of the machine we are logging from.
	LogLevel       logrus.Level // Log level of messages we want to send to socket.
	Service        string       // Service that is creating the logs.
	SocketAddr     string       // Address to the socket.
	SocketProtocol string       // Protocol of the socket.
	AddNewLine     bool         // Toggle to send newline after every message to socket.
}

Config serves as means to configure logger and hook.

type Hook

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

Hook represents a connection to a socket

func NewHook

func NewHook(protocol, address string, addNewline bool) (*Hook, error)

NewHook establish a socket connection. Protocols allowed are: "udp", "tcp", "unix" (corresponds to SOCK_STREAM), "unixdomain" (corresponds to SOCK_DGRAM) or "unixpacket" (corresponds to SOCK_SEQPACKET).

For TCP and UDP, address must have the form `host:port`.

For Unix networks, the address must be a file system path.

func (*Hook) Fire

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

Fire send log to the defined socket

func (*Hook) Levels

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

Levels return an array of handled logging levels

Jump to

Keyboard shortcuts

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