loggers

package
v0.0.0-...-384a6d4 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DISCONNECTED = iota
	CONNECTED
	CONNECTING
)

connection status

View Source
const (
	LOGGER_REMOTE = "remote"
)
View Source
const (
	LOGGER_REMOTE_SYSLOG = "remote_syslog"
)
View Source
const (
	LOGGER_SYSLOG = "syslog"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger interface {
	Transform(...interface{}) string
	Write(string)
	Close() error
}

Logger is the common interface that every logger must met. Serves as a generic holder of different types of loggers.

type LoggerConfig

type LoggerConfig struct {
	// Name of the logger: syslog, elastic, ...
	Name string

	// Format: rfc5424, csv, json, ...
	Format string

	// Protocol: udp, tcp
	Protocol string

	// Server: 127.0.0.1:514
	Server string

	// WriteTimeout ...
	WriteTimeout string

	// ConnectTimeout ...
	ConnectTimeout string

	// Tag: opensnitchd, mytag, ...
	Tag string

	// Workers: number of workers
	Workers int

	// MaxConnectAttempts holds the max attemps to connect to the remote server.
	// A value of 0 will try to connect indefinitely.
	MaxConnectAttempts uint16
}

LoggerConfig holds the configuration of a logger

type LoggerManager

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

LoggerManager represents the LoggerManager.

func NewLoggerManager

func NewLoggerManager() *LoggerManager

NewLoggerManager instantiates all the configured loggers.

func (*LoggerManager) Load

func (l *LoggerManager) Load(configs []LoggerConfig)

Load loggers configuration and initialize them.

func (*LoggerManager) Log

func (l *LoggerManager) Log(args ...interface{})

Log sends data to the loggers.

func (*LoggerManager) Reload

func (l *LoggerManager) Reload()

Reload stops and loads the configured loggers again

func (*LoggerManager) Stop

func (l *LoggerManager) Stop()

Stop closes the opened loggers, and closes the workers

type Remote

type Remote struct {
	Writer *syslog.Writer

	// Name of the logger
	Name string

	Tag string

	// Name of the host where the daemon is running
	Hostname string

	// Write timeouts
	Timeout time.Duration

	// Connect timeout
	ConnectTimeout time.Duration
	// contains filtered or unexported fields
}

Remote defines a logger that writes events to a generic remote server. It can write to a local or a remote daemon, UDP or TCP. It supports writing events in RFC5424, RFC3164, CSV and JSON formats.

func NewRemote

func NewRemote(cfg LoggerConfig) (*Remote, error)

NewRemote returns a new object that manipulates and prints outbound connections to a remote server, with the given format (RFC5424 by default)

func (*Remote) Close

func (s *Remote) Close() (err error)

Close closes the writer object

func (*Remote) Dial

func (s *Remote) Dial(proto, addr string, connTimeout time.Duration) (netConn net.Conn, err error)

Dial opens a new connection with a remote server.

func (*Remote) Open

func (s *Remote) Open() (net.Conn, bool)

Open establishes a connection with a remote server. It'll try to reopen the connection based on the configuration provided: If MaxConnectAttempts is 0, indefinitely. Otherwise the amount of attempts specified.

func (*Remote) Transform

func (s *Remote) Transform(args ...interface{}) (out string)

Transform transforms data for proper ingestion.

func (*Remote) Write

func (s *Remote) Write(msg string)

type RemoteSyslog

type RemoteSyslog struct {
	*Remote
}

func NewRemoteSyslog

func NewRemoteSyslog(cfg LoggerConfig) (*RemoteSyslog, error)

NewRemoteSyslog returns a new object that manipulates and prints outbound connections to a remote syslog server, with the given format (RFC5424 by default)

type Syslog

type Syslog struct {
	Writer *syslog.Writer

	Name string
	Tag  string
	// contains filtered or unexported fields
}

Syslog defines the logger that writes traces to the syslog. It can write to the local or a remote daemon.

func NewSyslog

func NewSyslog(cfg LoggerConfig) (*Syslog, error)

NewSyslog returns a new object that manipulates and prints outbound connections to syslog (local or remote), with the given format (RFC5424 by default)

func (*Syslog) Close

func (s *Syslog) Close() error

Close closes the writer object

func (*Syslog) Open

func (s *Syslog) Open() error

Open opens a new connection with a server or with the daemon.

func (*Syslog) Transform

func (s *Syslog) Transform(args ...interface{}) (out string)

Transform transforms data for proper ingestion.

func (*Syslog) Write

func (s *Syslog) Write(msg string)

Jump to

Keyboard shortcuts

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