rfc5424

package module
v0.0.0-...-0001220 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2020 License: BSD-2-Clause Imports: 8 Imported by: 14

README

NOTE: This repository is deprecated in favor of go-loggregator

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

View Source
const RFC5424TimeOffsetNum = "2006-01-02T15:04:05.999999-07:00"

RFC5424TimeOffsetNum is the timestamp defined by RFC-5424 with the NUMOFFSET instead of Z.

View Source
const RFC5424TimeOffsetUTC = "2006-01-02T15:04:05.999999Z"

RFC5424TimeOffsetUTC is the timestamp defined by RFC-5424 with the offset set to 0 for UTC.

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