Nginx Error Log in PY
Parses Nginx error log lines.
Try it in the PY tester →Pattern
regexPY
^(\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}) \[(\w+)\] (\d+)#(\d+): (.*)$Python (re) code
pyPython
import re
pattern = re.compile(r"^(\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}) \[(\w+)\] (\d+)#(\d+): (.*)$")
input_text = "2023/10/11 10:00:00 [error] 1234#5678: *1 connect() 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
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() failedMatches
2023/10/11 10:00:00 [error] 1234#5678: *1 connect() failed