syslog

package module
v2.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 8 Imported by: 0

README

Syslog server library for go, build easy your custom syslog server over UDP, TCP or Unix sockets using RFC3164, RFC6587 or RFC5424

This library is based on https://github.com/mcuadros/go-syslog with the following pull requests applied:

Installation

The recommended way to install go-syslog

go get codeberg.org/athenax/go-syslog

Examples

How import the package

import "codeberg.org/athenax/go-syslog/v2"

Example of a basic syslog UDP server:

channel := make(syslog.LogPartsChannel)
handler := syslog.NewChannelHandler(channel)

server := syslog.NewServer()
server.SetFormat(syslog.RFC5424)
server.SetHandler(handler)
server.ListenUDP("0.0.0.0:514")
server.Boot()

go func(channel syslog.LogPartsChannel) {
    for logParts := range channel {
        fmt.Println(logParts)
    }
}(channel)

server.Wait()

License

MIT, see LICENSE

Documentation

Overview

Syslog server library for go, build easy your custom syslog server over UDP, TCP or Unix sockets using RFC3164, RFC5424 and RFC6587

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type ChannelHandler

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

The ChannelHandler will send all the syslog entries into the given channel

func NewChannelHandler

func NewChannelHandler(channel LogPartsChannel) *ChannelHandler

NewChannelHandler returns a new ChannelHandler

func (*ChannelHandler) Handle

func (h *ChannelHandler) Handle(logParts format.LogParts, messageLength int64, err error)

Syslog entry receiver

func (*ChannelHandler) SetChannel

func (h *ChannelHandler) SetChannel(channel LogPartsChannel)

The channel to be used

type DatagramMessage

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

type Handler

type Handler interface {
	Handle(format.LogParts, int64, error)
}

The handler receive every syslog entry at Handle method

type HandshakeError

type HandshakeError struct {
	RemoteAddr      net.Addr
	ConnectionState tls.ConnectionState
	// contains filtered or unexported fields
}

func (*HandshakeError) Error

func (l *HandshakeError) Error() string

func (*HandshakeError) Unwrap

func (l *HandshakeError) Unwrap() error

type ListenerError

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

Error types

func (*ListenerError) Error

func (l *ListenerError) Error() string

func (*ListenerError) Unwrap

func (l *ListenerError) Unwrap() error

type LogPartsChannel

type LogPartsChannel chan format.LogParts

type ParserError

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

func (*ParserError) Error

func (l *ParserError) Error() string

func (*ParserError) Unwrap

func (l *ParserError) Unwrap() error

type ScanCloser

type ScanCloser struct {
	*bufio.Scanner
	// contains filtered or unexported fields
}

type ScannerError

type ScannerError struct {
	Client  string
	TLSPeer string
	// contains filtered or unexported fields
}

func (*ScannerError) Error

func (l *ScannerError) Error() string

func (*ScannerError) Unwrap

func (l *ScannerError) Unwrap() error

type Server

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

func NewServer

func NewServer() *Server

NewServer returns a new Server

func (*Server) Boot

func (s *Server) Boot() error

Starts the server, all the go routines goes to live

func (*Server) GetLastError

func (s *Server) GetLastError() error

Returns the last error

func (*Server) Kill

func (s *Server) Kill() error

Kill the server

func (*Server) ListenTCP

func (s *Server) ListenTCP(addr string) error

Configure the server for listen on a TCP addr

func (*Server) ListenTCPTLS

func (s *Server) ListenTCPTLS(addr string, config *tls.Config) error

Configure the server for listen on a TCP addr for TLS

func (*Server) ListenUDP

func (s *Server) ListenUDP(addr string) error

Configure the server for listen on an UDP addr

func (*Server) ListenUnixgram

func (s *Server) ListenUnixgram(addr string) error

Configure the server for listen on an unix socket

func (*Server) SetDatagramChannelSize

func (s *Server) SetDatagramChannelSize(size int)

func (*Server) SetDatagramReadBufferSize

func (s *Server) SetDatagramReadBufferSize(size int)

Sets datagram read buffer size

func (*Server) SetErrChannel

func (s *Server) SetErrChannel(c chan error)

Sets a channel for errors

func (*Server) SetFormat

func (s *Server) SetFormat(f format.Format)

Sets the syslog format (RFC3164 or RFC5424 or RFC6587)

func (*Server) SetHandler

func (s *Server) SetHandler(handler Handler)

Sets the handler, this handler with receive every syslog entry

func (*Server) SetTimeout

func (s *Server) SetTimeout(millseconds int64)

Sets the connection timeout for TCP connections, in milliseconds

func (*Server) SetTlsHandshakeTimeout

func (s *Server) SetTlsHandshakeTimeout(d time.Duration)

func (*Server) SetTlsPeerNameFunc

func (s *Server) SetTlsPeerNameFunc(tlsPeerNameFunc TlsPeerNameFunc)

Set the function that extracts a TLS peer name from the TLS connection

func (*Server) Wait

func (s *Server) Wait()

Waits until the server stops

type TimeoutCloser

type TimeoutCloser interface {
	Close() error
	SetReadDeadline(t time.Time) error
}

type TlsPeerNameFunc

type TlsPeerNameFunc func(tlsConn *tls.Conn) (tlsPeer string, ok bool)

A function type which gets the TLS peer name from the connection. Can return ok=false to terminate the connection

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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