syslog5424

package module
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2020 License: BSD-2-Clause Imports: 15 Imported by: 0

README

Syslog5424

License Go Doc Build Status Go Report Card

Example

import	(
	"github.com/nathanaelle/syslog5424"
)

type someSD struct{
	Message string
	Errno int
}

func main() {
	// create a connection to a server
	sl_conn, _, _ := syslog5424.Dial( "stdio", "stderr:" )

	// create a syslog wrapper around the connection
	syslog,_ := syslog5424.New( sl_conn, syslog5424.LogDAEMON|syslog5424.LogWARNING, "test-app" )

	// create a channel for errors
	err_channel	:= syslog.Channel( syslog5424.LogERR )

	// plug the golang log.Logger API to this channel
	logger_err := err_channel.Logger( "ERR : " )

	// log a message through the log.Logger
	logger_err.Print( "doing some stuff" )

	// log a message directly with some structured data
	err_channel.Log( "another message", someSD{ "some message", 42 } )
}

Features

Generic Features
  • golang log.Logger compliant
  • Handle multiple logging Channels
  • Provide /dev/null Channel
  • Extendable interfaces
RFC 5424
  • Encode RFC 5424 Message
  • Decode RFC 5424 Message
  • Encode Structured Data
  • Decode Structured Data
Networking / Communication
  • Dial to a AF_UNIX datagram syslog server
  • Dial to a AF_UNIX stream syslog server
  • Dial to a TCP remote syslog server
  • Accept to a AF_UNIX datagram syslog server
  • Accept to a AF_UNIX stream syslog server
  • Accept to a TCP remote syslog server
Transport Encoding
  • Unix Datagram Transport
  • NULL terminated Transport
  • LF terminated Transport
  • RFC 5425 Transport
Structured Data
  • Encode Structured Data
  • Decode Structured Data
  • Encode Private Structured Data
  • Decode Private Structured Data
  • Decode Unknown Structured Data
  • Structured Data Interface
  • SDID Interface
  • SDIDLight Interface for Light Structured Data Support
Structured Data Type

Source : IANA syslog Structured Data ID Values

  • timeQuality (RFC 5424)
  • meta (RFC 5424)
  • origin (RFC 5424)
  • snmp (RFC 5675)
  • alarm (RFC 5674)
  • ssign (RFC 5848)
  • ssign-cert (RFC 5848)
  • PCNNode (RFC 6661)
  • PCNTerm (RFC 6661)

License

2-Clause BSD

Questions

What is Syslog5424 ?

Syslog5424 is a library for coping with syslog messages through the log.Logger API. Syslog5424 only produces syslog packets that are compatible with RFC 5424. Those messages are not compatible with RFC 3164.

What is Structured Data ?

The main point of the RFC 5424 is structured data. This is a textual serialization of simple struct or map[string]string. This serialization is typed or named and one text message can convey many Structured Data entries. So This is a very pertinent way to mix metrics, keywords and human readable messages.

What there is no support of UDP (RFC 5426) ?

System logging must be reliable for security audits of the logs. UDP is an unreliable protocol because UDP packets can be dropped, and neither the client nor the server will be informed of the missing data.

Why remove parts of code about TLS ?

TLS is supported because the networking is implemented as interfaces. but my idea of "security" is not compatible with maintaining duplicate code.

The requirements to support TLS are :

  1. Verify the certificate validity
  2. verify the chain of trust to the root
  3. Verify OSCP staple if provided
  4. Check the OSCP's response from the CA
  5. Verify the SCT with the OSCP's SCT information and/or SCT extra TLS header

so, you can :

  1. Write your own code with the golang TLS stack (everything is provided through interfaces)
  2. Wait for my implementation with the golang TLS stack wich will provide OCSP and Public Key verification

Todo

  • Write documentation
  • Write comments

Documentation

Overview

Package syslog5424 implements syslog RFC 5424 with a complete compatibility with the standard log.Logger API.

the simpliest way to use syslog5424 is :

package main

import	(
	"github.com/nathanaelle/syslog5424"
)

func main() {
	// create a connection the standard error
	sl_conn, _, _ := syslog5424.Dial( "stdio", "stderr:" )

	// create a syslog wrapper around the connection
	// the program is named "test-app" and you log to LogDAEMON facility at least at LogWARNING level
	syslog,_ := syslog5424.New( sl_conn, syslog5424.LogDAEMON|syslog5424.LogWARNING, "test-app" )

	// create a channel for the level LogERR
	err_channel	:= syslog.Channel( syslog5424.LogERR )

	// get a the *log.Logger for this channel with a prefix "ERR : "
	logger_err := err_channel.Logger( "ERR : " )

	// log a message through the log.Logger
	logger_err.Print( "doing some stuff" )
}

Index

Examples

Constants

View Source
const RFC5424TimeStamp string = "2006-01-02T15:04:05.999999Z07:00"

RFC5424TimeStamp is the format of a RFC 5424 TimeStamp

Variables

View Source
var (
	ErrBufferClose = errors.New("error in syslog5424 at buffer.Close()")
	ErrNoConnecion = errors.New("No Connection established")

	ErrPos0                = errors.New("Pos 0 Found")
	ErrPosNotFound         = errors.New("Pos Not Found")
	ErrImpossible          = errors.New("NO ONE EXPECT THE RETURN OF SPANISH INQUISITION")
	ErrInvalidNetwork      = errors.New("Invalid Network")
	ErrInvalidAddress      = errors.New("Invalid Address")
	ErrEmptyNetworkAddress = errors.New("Empty Network or Address")

	ErrTransportIncomplete = errors.New("Transport : Incomplete Message")
	ErrTransportNoHeader   = errors.New("T_RFC5425 Split: no header len")
	ErrTransportInvHeader  = errors.New("T_RFC5425 Split: invalid header len")
)
View Source
var (
	// Now permit to change the local default alias function for time.Now(). only usefull in case of test or debug
	Now = time.Now
)

Functions

func GenericSD

func GenericSD(i sdata.SDIDLight) sdata.StructuredData

GenericSD is a wrapper around sdata.GenericSD

Types

type Addr

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

Addr see net.Addr

func (*Addr) Network

func (a *Addr) Network() string

Network see net.Addr

func (*Addr) String

func (a *Addr) String() string

type Channel

type Channel interface {
	io.Writer
	IsDevNull() bool
	AppName(string) Channel
	Msgid(string) Channel
	Logger(string) *log.Logger
	Log(string, ...sdata.StructuredData)
}

Channel interface describe the common API of any logging channel. a logging channel is a context set for any log message or structured data

type Connector

type Connector interface {
	Connect() (WriteCloser, error)
}

Connector describe the generic way to create a WriteCloser

func LocalConnector

func LocalConnector(network, address string) Connector

LocalConnector is a dialer that forward to a local RFC5424 syslog receiver

func StdioConnector

func StdioConnector(addr string) Connector

StdioConnector returns a Connector that only forward to stderr: or stdout:

func TCPConnector

func TCPConnector(network, address string) Connector

TCPConnector is a dialer that forward to a local RFC5424 syslog receiver

type ConnectorFunc

type ConnectorFunc func() (WriteCloser, error)

ConnectorFunc is an helper that convert an function to a Connector

func (ConnectorFunc) Connect

func (f ConnectorFunc) Connect() (WriteCloser, error)

Connect implements Connector.Connect

type DataReader

type DataReader interface {
	io.Reader
	io.Closer

	// RemoteAddr returns the remote network address.
	RemoteAddr() net.Addr
}

DataReader describe an incoming connexion

type Dialer

type Dialer struct {
	// delay to flush the queue
	FlushDelay time.Duration
}

Dialer contains options for connecting to an address.

func (Dialer) Dial

func (d Dialer) Dial(network, address string, t Transport) (*Sender, <-chan error, error)

Dial opens a connection to the syslog daemon network can be "stdio", "unix", "unixgram", "tcp", "tcp4", "tcp6" Transport can be nil. if Transport is nil the "common" transport for the wished network is used.

the returned `<-chan error` is used to collect errors than may occur in goroutine

type InvalidConnector

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

InvalidConnector is a connector that always return an error

func (InvalidConnector) Connect

func (ic InvalidConnector) Connect() (conn WriteCloser, err error)

Connect is part of implementation of (Connector interface)[#Connector]

type Listener

type Listener interface {

	// Accept waits for and returns the next DataReader to the listener.
	Accept() (DataReader, error)

	// Close closes the listener.
	Close() error
}

Listener decribe a generic way to Listen for an incoming connexion

Example (Basic)
package main

import (
	"fmt"
	"log"
	"os"
	"sync"
	"time"
)

const TestSOCKET string = "./test.socket"

func main() {
	defer os.Remove(TestSOCKET)

	wg := new(sync.WaitGroup)
	mutex := new(sync.Mutex)

	mutex.Lock()

	Now = func() time.Time {
		t, _ := time.ParseInLocation("2006-01-02T15:04:00Z", "2014-12-20T14:04:00Z", time.UTC)
		return t
	}

	wg.Add(2)
	go server(wg, mutex)
	go client(wg, mutex)

	wg.Wait()
	mutex.Unlock()

}

func client(wg *sync.WaitGroup, mutex *sync.Mutex) {
	defer wg.Done()

	// waiting the creation of the socket
	mutex.Lock()
	slConn, chanErr, err := Dial("unix", TestSOCKET)
	if err != nil {
		log.Fatal(err)
	}

	go func() {
		if err := <-chanErr; err != nil {
			log.Fatal(err)
		}
	}()

	syslog, err := New(slConn, LogDAEMON|LogWARNING, "client-app")
	if err != nil {
		log.Fatal(err)
	}
	syslog.TestMode()

	loggerErrConf := syslog.Channel(LogERR).Logger("ERR : ")

	loggerErrConf.Print("doing some stuff")
	loggerErrConf.Print("doing anoter stuff")
	loggerErrConf.Print("doing a last stuff")

	slConn.End()
}

func server(wg *sync.WaitGroup, mutex *sync.Mutex) {
	defer wg.Done()

	listener, err := UnixListener(TestSOCKET)
	if err != nil {
		log.Fatal(err)
	}
	collect, chanErr := NewReceiver(listener, 100, TransportZeroEnded)

	go func() {
		if err := <-chanErr; err != nil {
			log.Fatalf("client chanErr %q", err)
		}
	}()

	// socket is created
	mutex.Unlock()

	count := 3
	for count > 0 {
		count--

		msg, err, _ := collect.Receive()
		if err != nil {
			log.Fatal(err)
		}

		fmt.Printf("%s\n", msg.String())
	}

	collect.End()
}
Output:

<27>1 2014-12-20T14:04:00Z localhost client-app 1234 - - ERR : doing some stuff
<27>1 2014-12-20T14:04:00Z localhost client-app 1234 - - ERR : doing anoter stuff
<27>1 2014-12-20T14:04:00Z localhost client-app 1234 - - ERR : doing a last stuff
Example (Custom)
package main

import (
	"fmt"
	"log"
	"os"
	"sync"
	"time"
)

const TestSOCKET2 string = "./test-custom.socket"

func main() {
	defer os.Remove(TestSOCKET2)

	wg := new(sync.WaitGroup)
	mutex := new(sync.Mutex)

	mutex.Lock()

	Now = func() time.Time {
		t, _ := time.ParseInLocation("2006-01-02T15:04:00Z", "2014-12-20T14:04:00Z", time.UTC)
		return t
	}

	wg.Add(2)
	go serverCustom(wg, mutex)
	go clientCustom(wg, mutex)

	wg.Wait()
	mutex.Unlock()

}

func clientCustom(wg *sync.WaitGroup, mutex *sync.Mutex) {
	defer wg.Done()

	// waiting the creation of the socket
	mutex.Lock()
	slConn, chanErr, err := (Dialer{
		FlushDelay: 100 * time.Millisecond,
	}).Dial("unix", TestSOCKET2, TransportRFC5425)
	if err != nil {
		log.Fatal(err)
	}

	go func() {
		if err := <-chanErr; err != nil {
			log.Fatal(err)
		}
	}()

	syslog, err := New(slConn, LogDAEMON|LogWARNING, "custom-app")
	if err != nil {
		log.Fatal(err)
	}
	syslog.TestMode()

	loggerErrConf := syslog.Channel(LogERR).Logger("ERR : ")

	loggerErrConf.Print("doing some stuff")
	loggerErrConf.Print("doing anoter stuff")
	loggerErrConf.Print("doing a last stuff")

	slConn.End()
}

func serverCustom(wg *sync.WaitGroup, mutex *sync.Mutex) {
	defer wg.Done()

	listener, err := UnixListener(TestSOCKET2)
	if err != nil {
		log.Fatalf("server Collect %q", err)
	}

	collect, chanErr := NewReceiver(listener, 100, TransportRFC5425)

	go func() {
		if err := <-chanErr; err != nil {
			log.Fatalf("client chanErr %q", err)
		}
	}()

	// socket is created
	mutex.Unlock()

	count := 3
	for count > 0 {
		count--

		msg, err, _ := collect.Receive()
		if err != nil {
			log.Fatal(err)
		}

		fmt.Printf("%s\n", msg.String())
	}

	collect.End()
}
Output:

<27>1 2014-12-20T14:04:00Z localhost custom-app 1234 - - ERR : doing some stuff
<27>1 2014-12-20T14:04:00Z localhost custom-app 1234 - - ERR : doing anoter stuff
<27>1 2014-12-20T14:04:00Z localhost custom-app 1234 - - ERR : doing a last stuff

func GuessListener

func GuessListener(network, address string) (Listener, error)

GuessListener guess the correct Listener when network is not known at compilation time

func TCPListener

func TCPListener(network, address string) (Listener, error)

TCPListener create a TCP Listener

Example
package main

import (
	"fmt"
	"log"
	"sync"
	"time"
)

const testTCPSocket string = "127.0.0.1:51400"

func main() {
	wg := new(sync.WaitGroup)
	mutex := new(sync.Mutex)

	mutex.Lock()

	Now = func() time.Time {
		t, _ := time.ParseInLocation("2006-01-02T15:04:00Z", "2014-12-20T14:04:00Z", time.UTC)
		return t
	}

	wg.Add(2)
	go exTCPServer(wg, mutex)
	go exTCPClient(wg, mutex)

	wg.Wait()
	mutex.Unlock()

}

func exTCPClient(wg *sync.WaitGroup, mutex *sync.Mutex) {
	defer wg.Done()

	// waiting the creation of the socket
	mutex.Lock()
	slConn, chanErr, err := Dial("tcp", testTCPSocket)
	if err != nil {
		log.Fatal(err)
	}

	go func() {
		if err := <-chanErr; err != nil {
			log.Fatal(err)
		}
	}()

	syslog, err := New(slConn, LogDAEMON|LogWARNING, "client-app")
	if err != nil {
		log.Fatal(err)
	}
	syslog.TestMode()

	loggerErrConf := syslog.Channel(LogERR).Logger("ERR : ")

	loggerErrConf.Print("doing some stuff")
	loggerErrConf.Print("doing anoter stuff")
	loggerErrConf.Print("doing a last stuff")

	slConn.End()
}

func exTCPServer(wg *sync.WaitGroup, mutex *sync.Mutex) {
	defer wg.Done()

	listener, err := TCPListener("tcp", testTCPSocket)
	if err != nil {
		log.Fatal(err)
	}

	collect, chanErr := NewReceiver(listener, 100, TransportLFEnded)

	go func() {
		if err := <-chanErr; err != nil {
			log.Fatalf("client chanErr %q", err)
		}
	}()

	// socket is created
	mutex.Unlock()

	count := 3
	for count > 0 {
		count--

		msg, err, _ := collect.Receive()
		if err != nil {
			log.Fatal(err)
		}

		fmt.Printf("%s\n", msg.String())
	}

	collect.End()
}
Output:

<27>1 2014-12-20T14:04:00Z localhost client-app 1234 - - ERR : doing some stuff
<27>1 2014-12-20T14:04:00Z localhost client-app 1234 - - ERR : doing anoter stuff
<27>1 2014-12-20T14:04:00Z localhost client-app 1234 - - ERR : doing a last stuff

func UnixListener

func UnixListener(address string) (Listener, error)

UnixListener create a UNIX Listener careful : a previous unused socket may be removed and recreated

func UnixgramListener

func UnixgramListener(address string) (Listener, error)

UnixgramListener create a Listener for UNIX datagram

type Message

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

Message describe a mutable Syslog 5424 Message

func CreateMessage

func CreateMessage(appname string, prio Priority, message string) Message

CreateMessage create a Message with the timestamp, hostname, appname, the priority and the message preset

func CreateWholeMessage

func CreateWholeMessage(prio Priority, ts time.Time, host, app, pid, msgid, message string) Message

CreateWholeMessage create a whole Message

func EmptyMessage

func EmptyMessage() Message

EmptyMessage create an empty Message

func (Message) AppName

func (msg Message) AppName(appname string) Message

AppName set the app-name of a Message

func (Message) Delta

func (msg Message) Delta(bootTs time.Time, strSec string, strNsec string) Message

Delta set the timestamp from a time elapsed since boot time

func (Message) Epoch

func (msg Message) Epoch(strSec string, strNsec string) Message

Epoch set the date of a Message with a epoch TimeStamp

func (Message) Host

func (msg Message) Host(host string) Message

Host set the app-name of a Message

func (Message) LocalHost

func (msg Message) LocalHost() Message

LocalHost set the hostname as the value get with gethostbyname()

func (Message) Marshal5424

func (msg Message) Marshal5424() ([]byte, error)

Marshal5424 encode a message to the syslog 5424 format

func (Message) Msg

func (msg Message) Msg(message string) Message

Msg set the message part of a Message

func (Message) MsgID

func (msg Message) MsgID(msgid string) Message

MsgID set the msg-id of a Message

func (Message) Now

func (msg Message) Now() Message

Now set the timestamp to time.Now()

func (Message) Priority

func (msg Message) Priority(prio Priority) Message

Priority set the priority of a Message

func (Message) ProcID

func (msg Message) ProcID(procid string) Message

ProcID set the proc-id of a Message

func (Message) String

func (msg Message) String() (s string)

func (Message) StructuredData

func (msg Message) StructuredData(data ...sdata.StructuredData) Message

StructuredData set the message part of a Message

func (Message) Time

func (msg Message) Time(ts time.Time) Message

Time set the timestamp of a Message

func (Message) Timestamp

func (msg Message) Timestamp(stamp string) Message

Timestamp set the timestamp from a time.Stamp string

type MessageImmutable

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

MessageImmutable is an incoming message from a remote agent. So it's a read only structure.

func Parse

func Parse(data []byte, transport Transport, atEOF bool) (returnMsg MessageImmutable, rest []byte, mainErr error)

Parse allow to parse a []byte and decode one ImmutableMessage

func (MessageImmutable) AppName

func (msg MessageImmutable) AppName() (app string)

AppName return the appname field of a MessageImmutable

func (MessageImmutable) Hostname

func (msg MessageImmutable) Hostname() (host string)

Hostname return the hostname field of a MessageImmutable

func (MessageImmutable) MsgID

func (msg MessageImmutable) MsgID() (msgid string)

MsgID return the msgid field of a MessageImmutable

func (MessageImmutable) Priority

func (msg MessageImmutable) Priority() (prio Priority)

Priority return the priority field of a MessageImmutable

func (MessageImmutable) ProcID

func (msg MessageImmutable) ProcID() (procid string)

ProcID return the procid field of a MessageImmutable

func (MessageImmutable) String

func (msg MessageImmutable) String() string

func (MessageImmutable) StructuredData

func (msg MessageImmutable) StructuredData() (lsd sdata.List)

StructuredData return the Structured Data list of a MessageImmutable

func (MessageImmutable) Text

func (msg MessageImmutable) Text() (text string)

Text return the text field of a MessageImmutable

func (MessageImmutable) TimeStamp

func (msg MessageImmutable) TimeStamp() (ts time.Time)

TimeStamp return the timestamp field of a MessageImmutable

func (MessageImmutable) Writable

func (msg MessageImmutable) Writable() Message

Writable convert a MessageImmutable to Message

func (MessageImmutable) WriteTo

func (msg MessageImmutable) WriteTo(w io.Writer) (n int64, err error)

WriteTo implements io.WriterTo in MessageImmutable

type ParseError

type ParseError struct {
	Buffer  []byte
	Pos     int
	Message string
}

ParseError describe an error in parsing

func (ParseError) Error

func (pe ParseError) Error() string

type Priority

type Priority int

Priority is the encoded form of the severity and facility of a Message

const (
	LogEMERG Priority = iota
	LogALERT
	LogCRIT
	LogERR
	LogWARNING
	LogNOTICE
	LogINFO
	LogDEBUG
)

Severity.

const (
	LogKERN Priority = iota << 3
	LogUSER
	LogMAIL
	LogDAEMON
	LogAUTH
	LogSYSLOG
	LogLPR
	LogNEWS
	LogUUCP
	LogCRON
	LogAUTHPRIV
	LogFTP

	LogLOCAL0
	LogLOCAL1
	LogLOCAL2
	LogLOCAL3
	LogLOCAL4
	LogLOCAL5
	LogLOCAL6
	LogLOCAL7
)

Facility.

func (Priority) Facility

func (p Priority) Facility() Priority

Facility return the facility part of a priority

func (Priority) Marshal5424

func (p Priority) Marshal5424() (data []byte, err error)

Marshal5424 encode the priority to Syslog5424 format

func (*Priority) Set

func (p *Priority) Set(d string) error

Set implement flag.Value interface

func (Priority) Severity

func (p Priority) Severity() Priority

Severity return the severity part of a priority

func (Priority) String

func (p Priority) String() string

func (*Priority) Unmarshal5424

func (p *Priority) Unmarshal5424(d []byte) error

Unmarshal5424 decode the priority to Syslog5424 format

type Receiver

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

Receiver describe how message are received and decoded

func NewReceiver

func NewReceiver(listener Listener, lenQueue int, t Transport) (*Receiver, <-chan error)

NewReceiver create a new Listener

if Transport is nil then the function returns nil, nil this case may occurs when transport is unknown at compile time

the returned `<-chan error` is used to collect errors than may occur in goroutine

func (*Receiver) End

func (r *Receiver) End()

End terminate the log_collector goroutine

func (*Receiver) Receive

func (r *Receiver) Receive() (MessageImmutable, error, bool)

Receive an incoming syslog message and a possible error that occured during the decoding of this syslog message

type Sender

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

Sender describe the generic algorithm for sending Message through a connection

func Dial

func Dial(network, address string) (*Sender, <-chan error, error)

Dial opens a connection to the syslog daemon network can be "stdio", "unix", "unixgram", "tcp", "tcp4", "tcp6" used Transport is the "common" transport for the network. FlushDelay is preset to 500ms

Example (Stdio)
package main

import (
	"log"
	"time"
)

func main() {
	Now = func() time.Time {
		t, _ := time.ParseInLocation("2006-01-02T15:04:00Z", "2014-12-20T14:04:00Z", time.UTC)
		return t
	}

	slConn, _, err := Dial("stdio", "stdout:")
	if err != nil {
		log.Fatal(err)
	}

	syslog, err := New(slConn, LogDAEMON|LogWARNING, "test-app")
	if err != nil {
		log.Fatal(err)
	}
	syslog.TestMode()

	conflog := syslog.SubSyslog("configuration")

	// using standard "log" API from golang
	loggerInfoConf := conflog.Channel(LogINFO).Logger("INFO : ")
	loggerErrConf := conflog.Channel(LogERR).Logger("ERR : ")

	// this is not logged because line 25 tell to syslog to log LogWARNING or higher
	loggerInfoConf.Print("doing some stuff but not logged")

	loggerErrConf.Print("doing some stuff")

	// using internal API
	conflog.Channel(LogERR).Log("another message with structured data", GenericSD(someSD{"some message", 42}))

	// closing the connection and flushing all remaining logs
	slConn.End()

}

type someSD struct {
	Message string
	Errno   int
}

func (someSD) GetPEN() uint64 {
	return uint64(32473)
}

func (someSD) IsIANA() bool {
	return false
}

func (someSD) String() string {
	return "someSD@32473"
}
Output:

<27>1 2014-12-20T14:04:00Z localhost test-app/configuration 1234 - - ERR : doing some stuff
<27>1 2014-12-20T14:04:00Z localhost test-app/configuration 1234 - [someSD@32473 Message="some message" Errno="42"] another message with structured data

func NewSender

func NewSender(output Connector, transport Transport, ticker <-chan time.Time) (*Sender, <-chan error)

NewSender create a new sender

func (*Sender) End

func (c *Sender) End()

End terminate the log_sender goroutine

func (*Sender) Send

func (c *Sender) Send(m Message) (err error)

Send send a Message to the log_sender goroutine

type Syslog

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

Syslog describes a sysloger

func New

func New(output *Sender, minPriority Priority, appname string) (syslog *Syslog, err error)

New create a new Syslog

func (*Syslog) Channel

func (syslog *Syslog) Channel(sev Priority) Channel

Channel expose a custom channel for a priority

func (*Syslog) SubSyslog

func (syslog *Syslog) SubSyslog(subAppName string) (sub *Syslog)

SubSyslog create a syslog for a subAppName this allow to postfix to remplace the AppName with AppName/SubAppName

func (*Syslog) TestMode

func (syslog *Syslog) TestMode()

TestMode prefill hostname and pid. this is only for test purpose

type Transport

type Transport interface {
	// Set the sub conn where to write the transport-encoded data
	Encode([]byte) []byte

	// Decode the prefix in case of transport that use an encoding header
	PrefixStrip(buffer []byte, atEOF bool) (data, rest []byte, err error)

	// Decode the suffix in case of transport that use an encoding terminaison
	SuffixStrip(buffer []byte, atEOF bool) (data, rest []byte, err error)

	String() string
}

Transport describe a generic way to encode and decode syslog 5424 on an connexion

var (
	// TransportZeroEnded is commonly used transport with "unix" and "unixgram"
	TransportZeroEnded Transport = tZeroEnded{}

	// TransportLFEnded is commonly used transport with "tcp" "tcp4" and "tcp6"
	TransportLFEnded Transport = tLFEnded{}

	// TransportRFC5425 is performant transport specified in RFC 5425
	TransportRFC5425 Transport = tRFC5425{}
)

type WriteCloser

type WriteCloser interface {
	io.Writer
	io.Closer
}

WriteCloser is a generic interface describing a Connection

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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