simplesyslog

package module
v0.0.0-...-3d45942 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

README

simplesyslog

Build Status

Simple SYSLOG client in Go

Installation

go get github.com/NextronSystems/simplesyslog

Example Usage


import (
    syslog "github.com/NextronSystems/simplesyslog"
)

const SyslogServer = "<hostname>:<port>"

func main() {
    client, err := syslog.NewClient(syslog.ConnectionUDP, SyslogServer)
    if err != nil {
        ...
    }
    defer client.Close()
    if err := client.Send("foo bar baz", syslog.LOG_LOCAL0|syslog.LOG_NOTICE); err != nil {
        ...
    }
}

Documentation

Index

Constants

View Source
const (
	// DefaultHostname will be used if hostname could not be determined
	DefaultHostname string = "unknown"
	// DefaultIP will be used if ip could not be determined
	DefaultIP string = ""
)

Variables

View Source
var TooManyBytesSentErr = errors.New("too many bytes sent")

TooManyBytesSentErr will be returned, if a message could not be sent because of a hard limit of bytes to be send.

Functions

This section is empty.

Types

type Client

type Client struct {
	Hostname     string // Hostname of the system
	IP           string // IP of the system
	Rfc3164      bool   // rfc standard for length reduction
	Rfc5424      bool   // rfc standard for length reduction
	Rfc3339      bool   // use rfc3339 instead of stamp for time format
	MaxLength    int    // max syslog length
	NoPrio       bool   // do not add <prio> Prefix
	HostnameOnly bool   // Only use hostname in syslog header instead of hostname ip combination
	// contains filtered or unexported fields
}

Client holds a connection to a specified address

func NewClient

func NewClient(connectionType ConnectionType, address string, tlsconfig *tls.Config) (*Client, error)

NewClient initializes a new server connection. Examples:

  • NewClient(ConnectionUDP, "172.0.0.1:514")
  • NewClient(ConnectionTCP, ":514")
  • NewClient(ConnectionTLS, "172.0.0.1:514")

func (*Client) Close

func (client *Client) Close() error

Close closes the server connection gracefully.

func (*Client) Send

func (client *Client) Send(message string, priority Priority) error

Send sends a syslog message with a specified priority. Examples:

  • Send("foo", LOG_LOCAL0|LOG_NOTICE)
  • Send("bar", LOG_DAEMON|LOG_DEBUG)

func (*Client) SendRaw

func (client *Client) SendRaw(message string) error

SendRaw sends a syslog message without adding syslog header. Examples:

  • SendRaw("foo")
  • SendRaw("bar")

func (*Client) SetMaxBytes

func (client *Client) SetMaxBytes(i int64)

SetMaxBytes sets the maximum bytes that will be sent to rsyslog (approximately)

type ConnectionType

type ConnectionType string

ConnectionType defines wheather to connect via UDP or TCP (or TLS)

const (
	// ConnectionUDP connects via UDP
	ConnectionUDP ConnectionType = "udp"
	// ConnectionTCP connects via TCP
	ConnectionTCP ConnectionType = "tcp"
	// ConnectionTLS connects via TLS
	ConnectionTLS ConnectionType = "tls"
)

type Priority

type Priority int

Priority is the combination of severity and facility. (see go's syslog package for more infos)

const (
	LOG_EMERG Priority = iota
	LOG_ALERT
	LOG_CRIT
	LOG_ERR
	LOG_WARNING
	LOG_NOTICE
	LOG_INFO
	LOG_DEBUG
)

Severities

const (
	LOG_KERN Priority = iota << 3
	LOG_USER
	LOG_MAIL
	LOG_DAEMON
	LOG_AUTH
	LOG_SYSLOG
	LOG_LPR
	LOG_NEWS
	LOG_UUCP
	LOG_CRON
	LOG_AUTHPRIV
	LOG_FTP

	LOG_LOCAL0
	LOG_LOCAL1
	LOG_LOCAL2
	LOG_LOCAL3
	LOG_LOCAL4
	LOG_LOCAL5
	LOG_LOCAL6
	LOG_LOCAL7
)

Facilities

Jump to

Keyboard shortcuts

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