rfc5424

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2020 License: BSD-2-Clause Imports: 8 Imported by: 35

README

Build Status

This is a Go library that can read and write RFC-5424 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)

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrBadFormat

type ErrBadFormat struct {
	Property string
}

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

func (ErrBadFormat) Error

func (e ErrBadFormat) Error() string

type ErrInvalidValue

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

func (e ErrInvalidValue) Error() string

type Message

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

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

AddDatum adds structured data to a log message

func (Message) MarshalBinary

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

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

func (*Message) ReadFrom

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

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

UnmarshalBinary unmarshals a byte slice into a message

func (Message) WriteTo

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

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

type SDParam struct {
	Name  string
	Value string
}

SDParam represents parameters for structured data

type StructuredData

type StructuredData struct {
	ID         string
	Parameters []SDParam
}

StructuredData represents structured data within a log message

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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