Python (re)

Log Level in PY

Matches standard log level keywords in log lines.

Try it in the PY tester →

Pattern

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

Python (re) code

pyPython
import re

pattern = re.compile(r"\b(TRACE|DEBUG|INFO|WARN|ERROR|FATAL)\b")
input_text = "[INFO] Server started. [ERROR] Connection failed."
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

`\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)