Python (re)

Syslog (RFC 5424) in PY

Parses RFC 5424 syslog messages.

Try it in the PY tester →

Pattern

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

Python (re) code

pyPython
import re

pattern = re.compile(r"^<(\d{1,3})>(\d+) (\S+) (\S+) (\S+) (\S+) (\S+) (.*)$")
input_text = "<165>1 2023-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 - Application event"
for m in pattern.finditer(input_text):
    print(m.group(0))

Stdlib `re` module — no third-party dependency. Works on Python 3.6+.

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)