Nginx log_format and Apache LogFormat to Regex Converter
Converts a log format directive into a regular expression with named groups and tests it on a sample line.
Use the tool
Why this tool exists
Custom log formats are the usual reason a standard parser fails. Writing the regex by hand means escaping brackets and quotes for every field.
The tool maps each nginx variable or Apache code to a pattern, using the quotes or brackets around it to choose between a non-space, quoted or bracketed match. The result was tested against Python on sample lines. Odd content such as stray quotes in a user agent can still break a match.
How to use it
- Paste the log_format or LogFormat line.
- Paste one real log line as a sample.
- Check that every field is extracted.
- Copy the JavaScript or Python regex.
Frequently asked questions
Which variables are known?
The common nginx variables and Apache codes. Unknown ones get a safe non-space pattern.
Why does my sample not match?
A field may contain spaces or quotes the pattern does not allow. Adjust that group by hand.
Python or JavaScript?
Both are shown. Python uses (?P<name>) and JavaScript uses (?<name>).
Is my log uploaded?
No. Parsing happens in your browser and nothing is sent. Logs can hold IP addresses and tokens, so the page does not write them into the address bar.