JavaScript / ECMAScript

Syslog (RFC 5424) in JS

Parses RFC 5424 syslog messages.

Try it in the JS tester →

Pattern

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

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("^<(\\d{1,3})>(\\d+) (\\S+) (\\S+) (\\S+) (\\S+) (\\S+) (.*)$", "");
const input = "<165>1 2023-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 - Application event";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

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)