Documentation
¶
Overview ¶
Package parsesyslog implements a syslog message parser for different RFC log formats
Index ¶
- Constants
- Variables
- func FacilityStringFromPrio(p Priority) string
- func ParseUintBytes(b []byte) (int, error)
- func Register(parserType ParserType, newFunc newFunc)
- 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 expected 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") // ErrInvalidLength should be used if the length of the log message does not match the provided length ErrInvalidLength = errors.New("log message does not match the provided length value") // ErrInvalidNumber should be used if the number is not valid ErrInvalidNumber = errors.New("invalid number") )
Functions ¶
func FacilityStringFromPrio ¶
FacilityStringFromPrio returns a string representation of the Facility of a given Priority
func ParseUintBytes ¶ added in v0.3.0
ParseUintBytes parses a byte slice containing only numeric characters into an integer, returning an error for invalid input.
func Register ¶
func Register(parserType ParserType, newFunc newFunc)
Register adds a new parser factory function for a specified ParserType if it is not already registered.
func SeverityStringFromPrio ¶
SeverityStringFromPrio returns a string representation of the Severity of a given Priority
Types ¶
type Facility ¶
type Facility uint8
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 {
// Wide and/or bulky types first
Message bytes.Buffer
Timestamp time.Time
App []byte
Host []byte
MsgID []byte
PID []byte
StructuredData []StructuredDataElement
// Medium size types
Type LogMsgType
MsgLength int32
Facility Facility
Priority Priority
ProtoVersion ProtoVersion
Severity Severity
HasBOM bool
// contains filtered or unexported fields
}
LogMsg represents a Syslog message as defined by the Parser, with fields for structured and unstructured data
func (*LogMsg) AppName ¶
AppName returns the application name extracted from the LogMsg. It converts the App field from []byte to string.
type LogMsgType ¶
type LogMsgType string
LogMsgType represents the type of a Syslog message, typically defined by RFC specifications such as RFC3164 or RFC5424.
type Parser ¶
type Parser interface {
ParseReader(io.Reader) (LogMsg, error)
ParseString(s string) (LogMsg, error)
}
Parser defines an interface for parsing Syslog messages from various input sources into LogMsg objects.
func New ¶
func New(t ParserType) (Parser, error)
New creates a new Parser instance based on the provided ParserType. Returns an error if the requested ParserType is not registered. The ParserType must correspond to a key in the internal types registry.
type ParserType ¶
type ParserType string
ParserType is an alias type for a string. It represents a type of parser used to process and interpret log messages.
type Priority ¶
type Priority uint8
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 ProtoVersion ¶
type ProtoVersion uint8
ProtoVersion represents the version of the Syslog protocol as defined in RFC5424.
type Severity ¶
type Severity uint8
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 []byte
Param []StructuredDataParam
}
StructuredDataElement represents a structured data element in an RFC5424 Syslog message. See: https://datatracker.ietf.org/doc/html/rfc5424#section-6.3.1
func (*StructuredDataElement) IDString ¶ added in v0.3.0
func (s *StructuredDataElement) IDString() string
IDString returns the ID of the StructuredDataElement as a string.
type StructuredDataParam ¶
StructuredDataParam represents a key-value pair within a Structured Data element of an RFC5424 Syslog message. See: https://datatracker.ietf.org/doc/html/rfc5424#section-6.3.3
func (*StructuredDataParam) Name ¶
func (s *StructuredDataParam) Name() string
Name returns the key of the StructuredDataParam as a string.
func (*StructuredDataParam) Value ¶
func (s *StructuredDataParam) Value() string
Value returns the value of the StructuredDataParam as a string.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
stdin-parser
command
|
|
|
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 |