rfc: github.com/juju/rfc/rfc5424 Index | Files | Directories

package rfc5424

import "github.com/juju/rfc/rfc5424"

The rfc5424 package holds an implementation of a RFC 5424 syslog client along with types and functions that facilitate complying with the RFC.

Index

Package Files

client.go doc.go message.go priority.go structureddata.go util.go

Constants

const ProtocolVersion = 1

ProtocolVersion is the syslog protocol version implemented in this package.

type AppName Uses

type AppName string

AppName is the name of the originating app or device.

func (AppName) String Uses

func (an AppName) String() string

String is the RFC 5424 representation of the app name.

func (AppName) Validate Uses

func (an AppName) Validate() error

Validate ensures the that app name is correct.

type Client Uses

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

Client is a wrapper around a network connection to which syslog messages will be sent.

func Open Uses

func Open(host string, cfg ClientConfig, dial DialFunc) (*Client, error)

Open opens a syslog client to the given host address. If no dial func is provided then net.Dial is used.

func (Client) Close Uses

func (client Client) Close() error

Close closes the client's underlying connection.

func (Client) Send Uses

func (client Client) Send(msg Message) error

Send sends the syslog message over the client's connection.

type ClientConfig Uses

type ClientConfig struct {
    // MaxSize is the maximum allowed size for syslog messages sent
    // by the client. If not set then there is no maximum.
    MaxSize int

    // SendTImeout is the timeout that is used for each sent message.
    SendTimeout time.Duration
}

ClientConfig is the configuration for a syslog client.

type Conn Uses

type Conn interface {
    io.Closer

    // Write writes the message to the connection.
    Write([]byte) (int, error)

    // SetWriteDeadline sets the absolute time after which any write
    // to the connection will time out.
    SetWriteDeadline(time.Time) error
}

Conn is the subset of net.Conn needed for a syslog client.

type DialFunc Uses

type DialFunc func(network, address string) (Conn, error)

DialFunc is a function that may be used to open a network connection.

func TLSDialFunc Uses

func TLSDialFunc(cfg *tls.Config, timeout time.Duration) (DialFunc, error)

TLSDialFunc returns a dial function that opens a TLS connection. If the address passed to the returned func does not include a port then the default syslog TLS port (6514) will be used.

type Facility Uses

type Facility int

Facility is the system component for which the log record was created.

const (
    FacilityKern Facility
    FacilityUser // default
    FacilityMail
    FacilityDaemon
    FacilityAuth
    FacilitySyslog
    FacilityLPR
    FacilityNews
    FacilityUUCP
    FacilityCron
    FacilityAuthpriv
    FacilityFTP
    FacilityNTP

    FacilityLocal0
    FacilityLocal1
    FacilityLocal2
    FacilityLocal3
    FacilityLocal4
    FacilityLocal5
    FacilityLocal6
    FacilityLocal7
)

These are the supported logging facilities.

func (Facility) String Uses

func (f Facility) String() string

String returns the name of the facility.

func (Facility) Validate Uses

func (f Facility) Validate() error

Validate ensures that the facility is correct.

type Header struct {
    Priority

    // Timestamp indicates when the record was originally created.
    Timestamp Timestamp

    // Hostname identifies the machine that originally sent the
    // syslog message.
    Hostname Hostname

    // AppName identifies the device or application that originated
    // the syslog message.
    AppName AppName

    // ProcID is a value that is included in the message, having no
    // interoperable meaning, except that a change in the value
    // indicates there has been a discontinuity in syslog reporting.
    // The field does not have any specific syntax or semantics; the
    // value is implementation-dependent and/or operator-assigned.
    ProcID ProcID

    // MsgID identifies the type of message. Messages with the same
    // MsgID should reflect events with the same semantics. The MSGID
    // itself is a string without further semantics. It is intended
    // for filtering messages on a relay or collector.
    MsgID MsgID
}

Header holds the header portion of the log record.

func (Header) String Uses

func (h Header) String() string

String returns an RFC 5424 representation of the header.

func (Header) Validate Uses

func (h Header) Validate() error

Validate ensures that the header is correct.

type Hostname Uses

type Hostname struct {
    // FQDN is a fully-qualified domain name.
    //
    // See RFC 1034.
    FQDN string

    // StaticIP is a statically-assigned IP address.
    //
    // See RFC 1035 or 4291-2.2.
    StaticIP net.IP

    // Hostname is an unqualified host name.
    Hostname string

    // DyanmicIP is a dynamically-assigned IP address.
    //
    // See RFC 1035 or 4291-2.2.
    DynamicIP net.IP
}

Hostname hold the different possible values for an RFC 5424 value. The first non-empty field is the one that gets used.

func (Hostname) String Uses

func (h Hostname) String() string

String is the RFC 5424 representation of the hostname.

func (Hostname) Validate Uses

func (h Hostname) Validate() error

Validate ensures that the hostname is correct.

type Message Uses

type Message struct {
    Header
    StructuredData

    // Msg is the record's UTF-8 message string.
    Msg string
}

Message holds a single RFC-5424 log record.

See https://tools.ietf.org/html/rfc5424#section-6.

func (Message) String Uses

func (m Message) String() string

String returns the RFC 5424 representation of the log record.

func (Message) Validate Uses

func (m Message) Validate() error

Validate ensures that the record is correct.

type MsgID Uses

type MsgID string

MsgID identifies a syslog message type.

func (MsgID) String Uses

func (mid MsgID) String() string

String is the RFC representation of the message ID.

func (MsgID) Validate Uses

func (mid MsgID) Validate() error

Validate ensures that the message ID is correct.

type Priority Uses

type Priority struct {
    // Severity is the criticality of the log record.
    Severity Severity

    // Facility is the system component for which the log record
    // was created.
    Facility Facility
}

Priority identifies the importance of a log record.

func ParsePriority Uses

func ParsePriority(str string) (Priority, error)

ParsePriority converts a priority string back into a Priority.

func (Priority) String Uses

func (p Priority) String() string

String returns the RFC 5424 representation of the priority.

func (Priority) Validate Uses

func (p Priority) Validate() error

Validated ensures that the priority is correct.

type ProcID Uses

type ProcID string

ProcID identifies a group of syslog messages.

func (ProcID) String Uses

func (pid ProcID) String() string

String is the RFC representation of the proc ID.

func (ProcID) Validate Uses

func (pid ProcID) Validate() error

Validate ensures that the proc ID is correct.

type Severity Uses

type Severity int

Severity is the criticality of the log record.

const (
    SeverityEmergency Severity = iota
    SeverityAlert
    SeverityCrit
    SeverityError
    SeverityWarning
    SeverityNotice
    SeverityInformational
    SeverityDebug
)

These are the supported logging severity levels.

func (Severity) String Uses

func (s Severity) String() string

String returns the name of the severity.

func (Severity) Validate Uses

func (s Severity) Validate() error

Validate ensures that the severity is correct. This will fail only in cases where an unsupported int is converted into a Severity.

type StructuredData Uses

type StructuredData []StructuredDataElement

StructuredData holds the structured data of a log record, if any.

func (StructuredData) String Uses

func (sd StructuredData) String() string

String returns the RFC 5424 representation of the structured data.

func (StructuredData) Validate Uses

func (sd StructuredData) Validate() error

Validate ensures that the structured data is correct.

type StructuredDataElement Uses

type StructuredDataElement interface {
    // ID returns the "SD-ID" for the element.
    ID() StructuredDataName

    // Params returns all the elements items (if any), in order.
    Params() []StructuredDataParam

    // Validate ensures that the element is correct.
    Validate() error
}

StructuredDataElement, AKA "SD-ELEMENT", provides the functionality that StructuredData needs from each of its elements.

type StructuredDataName Uses

type StructuredDataName string

StructuredDataName is a single name used in an element or its params.

func (StructuredDataName) Validate Uses

func (sdn StructuredDataName) Validate() error

Validate ensures that the name is correct.

type StructuredDataParam Uses

type StructuredDataParam struct {
    // Name identifies the item relative to an element. Note that an
    // element may have more than one item with the same name.
    Name StructuredDataName

    // Value is the value associated with the item.
    Value StructuredDataParamValue
}

StructuredDataParam, AKA "SD-PARAM", is a single item in an element's list.

func (StructuredDataParam) String Uses

func (sdp StructuredDataParam) String() string

String returns the RFC 5424 representation of the item.

func (StructuredDataParam) Validate Uses

func (sdp StructuredDataParam) Validate() error

Validated ensures that the item is correct.

type StructuredDataParamValue Uses

type StructuredDataParamValue string // RFC 3629

StructuredDataParamValue is the value of a single element item.

func (StructuredDataParamValue) String Uses

func (sdv StructuredDataParamValue) String() string

String returns the RFC 5424 representation of the value. In particular, it escapes \, ", and ].

func (StructuredDataParamValue) Validate Uses

func (sdv StructuredDataParamValue) Validate() error

Validate ensures that the value is correct.

type Timestamp Uses

type Timestamp struct {
    time.Time
}

Timestamp is an RFC 5424 timestamp.

func (Timestamp) String Uses

func (t Timestamp) String() string

String returns the RFC 5424 representation of the timestamp. In particular, this is RFC 3339 with some restrictions and a special case of "-" for the zero value.

Directories

PathSynopsis
rfc5424testPackage rc5424test provides utilities for testing RFC 5424.
sdelementsThe sdelements package holds the implementations of the different RFC 5424 structured data elements.

Package rfc5424 imports 8 packages (graph) and is imported by 15 packages. Updated 2016-11-06. Refresh now. Tools for package owners.