syslog

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2014 License: Apache-2.0, BSD-3-Clause Imports: 8 Imported by: 0

README

syslog

GoDoc

Package syslog implements a syslog server library. It is based on RFC 3164, as such it does not properly parse packets with an RFC 5424 header format.

Documentation

Overview

Package syslog implements a syslog server library. It is based on RFC 3164, as such it does not properly parse packets with an RFC 5424 header format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseHandler

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

BaseHandler is designed to simplify the creation of real handlers. It implements Handler interface using nonblocking queuing of messages and simple message filtering.

func NewBaseHandler

func NewBaseHandler(qlen int, filter func(SyslogMessage) bool, ft bool) *BaseHandler

NewBaseHandler creates BaseHandler using a specified filter. If filter is nil or if it returns true messages are passed to BaseHandler internal queue (of qlen length). If filter returns false or ft is true messages are returned to server for future processing by other handlers.

func (*BaseHandler) End

func (h *BaseHandler) End()

End signals the server that the handler properly shutdown. You need to call End only if Get has returned nil before.

func (*BaseHandler) Get

func (h *BaseHandler) Get() SyslogMessage

Get returns first message from internal queue. It waits for message if queue is empty. It returns nil if there is no more messages to process and handler should shutdown.

func (*BaseHandler) Handle

Handle inserts m in an internal queue. It immediately returns even if queue is full. If m == nil it closes queue and waits for End method call before return.

func (*BaseHandler) Queue

func (h *BaseHandler) Queue() <-chan SyslogMessage

Queue returns the BaseHandler internal queue as a read-only channel. You can use it directly, especially if your handler needs to select from multiple channels or have to work without blocking. You need to check if this channel is closed by sender and properly shutdown in this case.

type Facility

type Facility byte

Facility represents a message source as defined by RFC 3164.

const (
	Kern     Facility = iota // kernel messages
	User                     // user-level messages
	Mail                     // mail system
	Daemon                   // system daemons
	Auth                     // security/authorization messages
	Syslog                   // messages internal to syslogd
	Lpr                      // line printer subsystem
	News                     // newtork news subsystem
	Uucp                     // UUCP subsystem
	Cron                     // cron messages
	Authpriv                 // security/authorization messages
	System0                  // historically FTP daemon
	System1                  // historically NTP subsystem
	System2                  // historically log audit
	System3                  // historically log alert
	System4                  // historically clock daemon, some operating systems use this for cron
	Local0                   // local use 0
	Local1                   // local use 1
	Local2                   // local use 2
	Local3                   // local use 3
	Local4                   // local use 4
	Local5                   // local use 5
	Local6                   // local use 6
	Local7                   // local use 7
)

The following is a list of Facilities as defined by RFC 3164.

func (Facility) String

func (f Facility) String() string

String returns a string representation of the Facility. This satisfies the fmt.Stringer interface.

type FatalLogger

type FatalLogger interface {
	Fatal(...interface{})
	Fatalf(format string, v ...interface{})
	Fatalln(...interface{})
}

FatalLogger is an interface for logging package internal fatal errors

type FileHandler

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

FileHandler implements Handler interface to save messages into a text file. It properly handles logrotate HUP signal (closes a file and tries to open/create new one).

func NewFileHandler

func NewFileHandler(filename string, qlen int, filter func(SyslogMessage) bool,
	ft bool) *FileHandler

NewFileHandler accepts all arguments expected by NewBaseHandler plus filename which is the path to the log file.

func (*FileHandler) Handle

Handle queues and dispatches a message. See BaseHandler.Handle

func (*FileHandler) SetLogger

func (h *FileHandler) SetLogger(l Logger)

SetLogger changes an internal logger used to log I/O errors. By default I/O errors are written to os.Stderr using log.Logger.

type Handler

type Handler interface {
	// Handle should return Message (maybe modified) for future processing by
	// other handlers or return nil. If Handle is called with nil message it
	// should complete all remaining work and properly shutdown before return.
	Handle(SyslogMessage) SyslogMessage
}

Handler handles syslog messages

type Logger

type Logger interface {
	Print(...interface{})
	Printf(format string, v ...interface{})
	Println(...interface{})
}

Logger is an interface for package internal (non fatal) logging

type Message

type Message struct {
	Msg string
}

Message defines a syslog message.

func (*Message) String

func (m *Message) String() string

type Server

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

Server is the wrapper for a syslog server.

func NewServer

func NewServer() *Server

NewServer creates an idle server.

func (*Server) AddHandler

func (s *Server) AddHandler(h Handler)

AddHandler adds h to internal ordered list of handlers

func (*Server) Listen

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

Listen starts gorutine that receives syslog messages on specified address. addr can be a path (for unix domain sockets) or host:port (for UDP).

func (*Server) SetLogger

func (s *Server) SetLogger(l FatalLogger)

SetLogger sets logger for server errors. A running server is rather quiet and logs only fatal errors using FatalLogger interface. By default standard Go logger is used so errors are writen to stderr and after that whole application is halted. Using SetLogger you can change this behavior (log erross elsewhere and don't halt whole application).

func (*Server) Shutdown

func (s *Server) Shutdown()

Shutdown stops server.

type Severity

type Severity byte

Severity represents a level of messsage importance.

const (
	// Emerg - system is unusable
	Emerg Severity = iota
	// Alert - immediate action required
	Alert
	// Crit - critical conditions
	Crit
	// Err - error conditions
	Err
	// Warning - warning conditions
	Warning
	// Notice - normal but significant condition
	Notice
	// Info - information message
	Info
	// Debug - debug-level message
	Debug
)

func (Severity) String

func (s Severity) String() string

String returns a string representation of the Severity. This satisfies the fmt.Stringer interface.

type SyslogMessage added in v0.13.0

type SyslogMessage interface {
	fmt.Stringer
}

Jump to

Keyboard shortcuts

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