JavaScript / ECMAScript

Log Level in JS

Matches standard log level keywords in log lines.

Try it in the JS tester →

Pattern

regexJS
\b(TRACE|DEBUG|INFO|WARN|ERROR|FATAL)\b   (flags: g)

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("\\b(TRACE|DEBUG|INFO|WARN|ERROR|FATAL)\\b", "g");
const input = "[INFO] Server started. [ERROR] Connection 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

`\b(TRACE|DEBUG|INFO|WARN|ERROR|FATAL)\b` matches any of the six standard log levels as whole words.

Examples

Input

[INFO] Server started. [ERROR] Connection failed.

Matches

  • INFO
  • ERROR

Input

DEBUG: cache miss

Matches

  • DEBUG

Same pattern, other engines

← Back to Log Level overview (all engines)