Documentation ¶
Overview ¶
Package parsesyslog implements a syslog message parser for different RFC log formats
Index ¶
- Constants
- Variables
- func Atoi(b []byte) (int, error)
- func FacilityStringFromPrio(p Priority) string
- func ParsePriority(r *bufio.Reader, buf *bytes.Buffer, lm *LogMsg) error
- func ReadBytesUntilSpace(r *bufio.Reader) ([]byte, int, error)
- func ReadBytesUntilSpaceOrNilValue(r *bufio.Reader, buf *bytes.Buffer) (int, error)
- func ReadMsgLength(r *bufio.Reader) (int, error)
- func Register(t ParserType, fn func() (Parser, error))
- func SeverityStringFromPrio(p Priority) string
- type Facility
- type LogMsg
- type LogMsgType
- type Parser
- type ParserType
- type Priority
- type ProtoVersion
- type Severity
- type StructuredDataElement
- type StructuredDataParam
Constants ¶
const SeverityMask = 0x07
SeverityMask is the bitmask representing the Severity in the Priority
Variables ¶
var ( // ErrInvalidPrio should be used if the PRI part of the message is not following the log format ErrInvalidPrio = errors.New("PRI header not a valid priority string") // ErrInvalidProtoVersion should be used if the protocol version part of the header is not following the log format ErrInvalidProtoVersion = errors.New("protocol version string invalid") // ErrInvalidTimestamp should be used if it was not possible to parse the timestamp of the log message ErrInvalidTimestamp = errors.New("timestamp does not conform the logging format") // ErrParserTypeUnknown is returned if a Parser is requested via New() which is not registered ErrParserTypeUnknown = errors.New("unknown parser type") // ErrPrematureEOF should be used in case a log message ends before the provided length ErrPrematureEOF = errors.New("log message is shorter than the provided length") // ErrWrongFormat should be used if a log messages does not comply with the logging format definitions ErrWrongFormat = errors.New("log message does not conform the logging format") // ErrWrongSDFormat should be used in case the structured data is not parsable ErrWrongSDFormat = errors.New("structured data does not conform the format") )
Functions ¶
func FacilityStringFromPrio ¶
FacilityStringFromPrio returns a string representation of the Facility of a given Priority
func ParsePriority ¶
ParsePriority will try to parse the priority part of the RFC3164 header See: https://tools.ietf.org/search/rfc3164#section-4.1.1
func ReadBytesUntilSpace ¶
ReadBytesUntilSpace is a helper method that takes a io.Reader and reads all bytes until it hits a Space character. It returns the read bytes, the amount of bytes read and an error if one occurred
func ReadBytesUntilSpaceOrNilValue ¶
ReadBytesUntilSpaceOrNilValue is a helper method that takes a io.Reader and reads all bytes until it hits a Space character or the NILVALUE ("-"). It returns the read bytes, the amount of bytes read and an error if one occurred
func ReadMsgLength ¶
ReadMsgLength reads the first bytes of the log message which represent the total length of the log message
func Register ¶
func Register(t ParserType, fn func() (Parser, error))
Register registers a new ParserType with its corresponding Parser function.
func SeverityStringFromPrio ¶
SeverityStringFromPrio returns a string representation of the Severity of a given Priority
Types ¶
type Facility ¶
type Facility int
Facility represents the facility part of the Syslog PRI header
func FacilityFromPrio ¶
FacilityFromPrio extracts the Facility from a given Priority
type LogMsg ¶
type LogMsg struct { AppName string Facility Facility HasBOM bool Hostname string // Message []byte Message bytes.Buffer MsgLength int MsgID string Priority Priority ProcID string ProtoVersion ProtoVersion Severity Severity StructuredData []StructuredDataElement Timestamp time.Time Type LogMsgType }
LogMsg represents a parsed syslog message
type LogMsgType ¶
type LogMsgType string
LogMsgType represents the type of message
const ( RFC3164 LogMsgType = "RFC3164" // RFC3164: legacy BSD-syslog RFC5424 LogMsgType = "RFC5424" // RFC5424: modern IETF-syslog )
LogMsgTypes
type Parser ¶
type Parser interface { ParseReader(io.Reader) (LogMsg, error) ParseString(s string) (LogMsg, error) }
Parser is an interface for parsing log messages.
func New ¶
func New(t ParserType) (Parser, error)
New returns a Parser of the specified ParserType and an error. It looks up the ParserType in the types map and if found, calls the corresponding Parser function to create a new Parser instance.
If the ParserType is not found in the map, it returns nil and ErrParserTypeUnknown.
type Priority ¶
type Priority int
Priority represents the Syslog PRI header
const ( Emergency Priority = iota // System is unusable Alert // Action must be taken immediately Crit // Critical conditions Error // Error conditions Warning // Warning conditions Notice // Normal but significant conditions Info // Informational messages Debug // Debug-level messages )
Severities
const ( Kern Priority = iota << 3 // Kernel messages User // User-level messages Mail // Mail system Daemon // System daemons Auth // Security/authentication messages Syslog // Messages generated internally by the syslog daemon LPR // Printer subsystem News // Network News subsystem UUCP // UUCP subsystem Cron // Cron subsystem AuthPriv // Security/authentication messages FTP // FTP daemon NTP // NTP subsystem Security // Log audit Console // Log alert SolarisCron // Scheduling daemon Local0 // Locally used facilities Local1 // Locally used facilities Local2 // Locally used facilities Local3 // Locally used facilities Local4 // Locally used facilities Local5 // Locally used facilities Local6 // Locally used facilities Local7 // Locally used facilities )
Facilities
type Severity ¶
type Severity int
Severity represents the serverity part of the Syslog PRI header
func SeverityFromPrio ¶
SeverityFromPrio extracts the Facility from a given Priority
type StructuredDataElement ¶
type StructuredDataElement struct { ID string Param []StructuredDataParam }
StructuredDataElement represents a structured data elements as defined in RFC5424 See: https://datatracker.ietf.org/doc/html/rfc5424#section-6.3.1
type StructuredDataParam ¶
StructuredDataParam represents a structured data param pair as defined in RFC5424 See: https://datatracker.ietf.org/doc/html/rfc5424#section-6.3.3
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
Package rfc3164 implements a go-parsesyslog parser for the syslog format as described in RFC3164
|
Package rfc3164 implements a go-parsesyslog parser for the syslog format as described in RFC3164 |
Package rfc5424 implements a go-parsesyslog parser for the syslog format as described in RFC5424
|
Package rfc5424 implements a go-parsesyslog parser for the syslog format as described in RFC5424 |