Documentation ¶
Overview ¶
Syslog server library. It is based on RFC 3164 so it doesn't parse properly packets with new header format (described in RFC 5424).
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 desigend for 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(*Message) bool, ft bool) *BaseHandler
NewBaseHandler creates BaseHandler using 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 handler properly shutdown. You need to call End only if Get has returned nil before.
func (*BaseHandler) Get ¶
func (h *BaseHandler) Get() *Message
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 ¶
func (h *BaseHandler) Handle(m *Message) *Message
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 *Message
Queue returns BaseHandler internal queue as read-only channel. You can use it directly, especially if your handler need 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 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 in the way 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 ¶
NewFileHandler accepts all arguments expected by NewBaseHandler plus filename which is the path to the log file.
func (*FileHandler) Handle ¶
func (h *FileHandler) Handle(m *Message) *Message
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 (mayby 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(*Message) *Message }
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 { Time time.Time Source net.Addr Facility Severity Timestamp time.Time // optional Hostname string // optional Tag string // message tag as defined in RFC 3164 Content string // message content as defined in RFC 3164 Tag1 string // alternate message tag (white rune as separator) Content1 string // alternate message content (white rune as separator) }
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) AddHandler ¶
AddHandler adds h to internal ordered list of handlers
func (*Server) Listen ¶
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).