rfc5424: github.com/crewjam/rfc5424 Index | Files | Directories

package rfc5424

import "github.com/crewjam/rfc5424"

Pacakge rfc5424 is a library for parsing and serializing RFC-5424 structured syslog messages.

Example usage:

m := rfc5424.Message{
    Priority:  rfc5424.Daemon | rfc5424.Info,
    Timestamp: time.Now(),
    Hostname:  "myhostname",
    AppName:   "someapp",
    Message:   []byte("Hello, World!"),
}
m.AddDatum("foo@1234", "Revision", "1.2.3.4")
m.WriteTo(os.Stdout)

Produces output like:

107 <7>1 2016-02-28T09:57:10.804642398-05:00 myhostname someapp - - [foo@1234 Revision="1.2.3.4"] Hello, World!

You can also use the library to parse syslog messages:

m := rfc5424.Message{}
_, err := m.ReadFrom(os.Stdin)
fmt.Printf("%s\n", m.Message)

Index

Package Files

marshal.go message.go rfc5424.go stream.go unmarshal.go

type ErrBadFormat Uses

type ErrBadFormat struct {
    Property string
}

ErrBadFormat is the error that is returned when a log message cannot be parsed

func (ErrBadFormat) Error Uses

func (e ErrBadFormat) Error() string

type ErrInvalidValue Uses

type ErrInvalidValue struct {
    Property string
    Value    interface{}
}

ErrInvalidValue is returned when a log message cannot be emitted because one of the values is invalid.

func (ErrInvalidValue) Error Uses

func (e ErrInvalidValue) Error() string

type Message Uses

type Message struct {
    Priority       Priority
    Timestamp      time.Time
    Hostname       string
    AppName        string
    ProcessID      string
    MessageID      string
    StructuredData []StructuredData
    Message        []byte
}

Message represents a log message as defined by RFC-5424 (https://tools.ietf.org/html/rfc5424)

func (*Message) AddDatum Uses

func (m *Message) AddDatum(ID string, Name string, Value string)

AddDatum adds structured data to a log message

func (Message) MarshalBinary Uses

func (m Message) MarshalBinary() ([]byte, error)

MarshalBinary marshals the message to a byte slice, or returns an error

func (*Message) ReadFrom Uses

func (m *Message) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads a single record from an RFC-5425 style stream of messages

func (*Message) UnmarshalBinary Uses

func (m *Message) UnmarshalBinary(inputBuffer []byte) error

UnmarshalBinary unmarshals a byte slice into a message

func (Message) WriteTo Uses

func (m Message) WriteTo(w io.Writer) (int64, error)

WriteTo writes the message to a stream of messages in the style defined by RFC-5425. (It does not implement the TLS stuff described in the RFC, just the length delimiting.

type Priority Uses

type Priority int
const (
    Emergency Priority = iota
    Alert
    Crit
    Error
    Warning
    Notice
    Info
    Debug
)
const (
    Kern Priority = iota << 3
    User
    Mail
    Daemon
    Auth
    Syslog
    Lpr
    News
    Uucp
    Cron
    Authpriv
    Ftp
    Local0
    Local1
    Local2
    Local3
    Local4
    Local5
    Local6
    Local7
)

type SDParam Uses

type SDParam struct {
    Name  string
    Value string
}

SDParam represents parameters for structured data

type StructuredData Uses

type StructuredData struct {
    ID         string
    Parameters []SDParam
}

StructuredData represents structured data within a log message

Directories

PathSynopsis
example

Package rfc5424 imports 8 packages (graph) and is imported by 3 packages. Updated 2017-03-26. Refresh now. Tools for package owners.