Go (RE2)

Syslog (RFC 5424) in GO

Parses RFC 5424 syslog messages.

Try it in the GO tester →

Pattern

regexGO
^<(\d{1,3})>(\d+) (\S+) (\S+) (\S+) (\S+) (\S+) (.*)$

Go (RE2) code

goGo
package main

import (
	"fmt"
	"regexp"
)

func main() {
	re := regexp.MustCompile(`^<(\d{1,3})>(\d+) (\S+) (\S+) (\S+) (\S+) (\S+) (.*)$`)
	input := `<165>1 2023-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 - Application event`
	for _, match := range re.FindAllString(input, -1) {
		fmt.Println(match)
	}
}

Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.

How the pattern works

Captures priority, version, timestamp, hostname, app-name, procid, msgid, and message content from standard structured syslog entries.

Examples

Input

<165>1 2023-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 - Application event

Matches

  • <165>1 2023-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 - Application event

Same pattern, other engines

← Back to Syslog (RFC 5424) overview (all engines)