JavaScript / ECMAScript

Nginx Error Log in JS

Parses Nginx error log lines.

Try it in the JS tester →

Pattern

regexJS
^(\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}) \[(\w+)\] (\d+)#(\d+): (.*)$

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("^(\\d{4}/\\d{2}/\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(\\w+)\\] (\\d+)#(\\d+): (.*)$", "");
const input = "2023/10/11 10:00:00 [error] 1234#5678: *1 connect() failed";
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 timestamp, log level, PID, TID, and the error message from standard Nginx error log format.

Examples

Input

2023/10/11 10:00:00 [error] 1234#5678: *1 connect() failed

Matches

  • 2023/10/11 10:00:00 [error] 1234#5678: *1 connect() failed

Same pattern, other engines

← Back to Nginx Error Log overview (all engines)