syslog: github.com/bmconklin/syslog Index | Files | Directories

package syslog

import "github.com/bmconklin/syslog"

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

Package Files

filehandler.go handler.go internallog.go message.go priority.go server.go

type BaseHandler Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Facility Uses

type Facility byte
const (
    Kern Facility = iota
    User
    Mail
    Daemon
    Auth
    Syslog
    Lpr
    News
    Uucp
    Cron
    Authpriv
    System0
    System1
    System2
    System3
    System4
    Local0
    Local1
    Local2
    Local3
    Local4
    Local5
    Local6
    Local7
)

func (Facility) String Uses

func (f Facility) String() string

type FatalLogger Uses

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

FatalLogger is an interface for logging package internal fatal errors

type FileHandler Uses

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 Uses

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

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

func (*FileHandler) Handle Uses

func (h *FileHandler) Handle(m *Message) *Message

func (*FileHandler) SetLogger Uses

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 Uses

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 Uses

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

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

type Message Uses

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)
}

func (*Message) NetSrc Uses

func (m *Message) NetSrc() string

NetSrc only network part of Source as string (IP for UDP or Name for UDS)

func (*Message) String Uses

func (m *Message) String() string

type Server Uses

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

func NewServer Uses

func NewServer() *Server

NewServer creates idle server

func (*Server) AddHandler Uses

func (s *Server) AddHandler(h Handler)

AddHandler adds h to internal ordered list of handlers

func (*Server) Listen Uses

func (s *Server) Listen(netType, 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 Uses

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 Uses

func (s *Server) Shutdown()

Shutdown stops server.

type Severity Uses

type Severity byte
const (
    Emerg Severity = iota
    Alert
    Crit
    Err
    Warning
    Notice
    Info
    Debug
)

func (Severity) String Uses

func (s Severity) String() string

Directories

PathSynopsis
example_server

Package syslog imports 12 packages (graph). Updated 2016-11-10. Refresh now. Tools for package owners.