Documentation
¶
Index ¶
- Constants
- Variables
- type Client
- func (client *Client) Close() error
- func (client *Client) Send(message string, priority Priority) error
- func (client *Client) SendJSON(message string) error
- func (client *Client) SendMasked(message string, priority Priority, maskedHostname string) error
- func (client *Client) SendRaw(message string) error
- func (client *Client) SetMaxBytes(i int64)
- type ConnectionType
- type ConnectionWriter
- type Priority
Constants ¶
const ( // DefaultHostname will be used if hostname could not be determined DefaultHostname string = "unknown" // DefaultIP will be used if host address could not be determined DefaultIP string = "" )
const ( Rfc3164 = 1024 Rfc5424 = 2048 Unlimited = 0 )
Variables ¶
var ErrTooManyBytesSent = errors.New("too many bytes sent")
ErrTooManyBytesSent will be returned, if a message could not be sent because of a hard limit of bytes to be sent.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
Hostname string // Hostname of the system
IP string // IP of the system
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")
- NewClient(ConnectionHTTP, "https://example.com:8080/syslog")
func (*Client) Send ¶
Send sends a syslog message with a specified priority. It adds a syslog header with timestamp, hostname and priority. Examples:
- Send("foo", LOG_LOCAL0|LOG_NOTICE)
- Send("bar", LOG_DAEMON|LOG_DEBUG)
func (*Client) SendJSON ¶
SendJSON sends a syslog message as a JSON message if applicable, i.e., if connection type is HTTP(S) Content-Type is set accordingly. Note: message should be valid JSON. No syslog header is added and a check for MaxLength is not applied here. Examples:
- SendRaw("foo")
- SendRaw("bar")
func (*Client) SendMasked ¶
SendMasked sends a syslog message with a specified priority. It adds a syslog header with timestamp, hostname and priority. If maskedHostname is provided, it will be used instead of the hostname/IP combination. Examples:
- Send("foo", LOG_LOCAL0|LOG_NOTICE, "")
- Send("bar", LOG_DAEMON|LOG_DEBUG, "myhost")
func (*Client) SendRaw ¶
SendRaw sends a syslog message without adding syslog header. Note: a check for MaxLength is not applied here. Examples:
- SendRaw("foo")
- SendRaw("bar")
func (*Client) SetMaxBytes ¶
SetMaxBytes sets the maximum bytes that will be sent to rsyslog
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" // ConnectionHTTP connects via HTTP(S) ConnectionHTTP ConnectionType = "http" )
type ConnectionWriter ¶
type ConnectionWriter interface {
// WriteString writes a string to the connection. If contentType is set, it will be
// used as the Content-Type header for HTTP(S) connections.
WriteString(s string, contentType string) (int, error)
// SourceIP returns the source IP of the connection.
SourceIP() (net.IP, error)
// Exceeds checks if the number of bytes written exceeds the specified byte limit.
Exceeds(byteLimit int64) bool
// Close closes the connection gracefully.
Close() error
}
connWriter is used to write to the connection.
func NewConnectionWriter ¶
func NewConnectionWriter(connectionType ConnectionType, address string, tlsconfig *tls.Config) (ConnectionWriter, error)