Skip to content

Instantly share code, notes, and snippets.

@vaquarkhan
Forked from wolf0403/access_log_parser.py
Created March 14, 2022 05:32
Show Gist options
  • Select an option

  • Save vaquarkhan/640121a95a9f96e3cef0304e1aae88ab to your computer and use it in GitHub Desktop.

Select an option

Save vaquarkhan/640121a95a9f96e3cef0304e1aae88ab to your computer and use it in GitHub Desktop.
Python re for Nginx access_log
# Modified by adding names from https://github.com/richardasaurus/nginx-access-log-parser/blob/master/main.py
pat = (r''
'(?P<ip>\d+.\d+.\d+.\d+)\s-\s-\s' #IP address
'\[(?P<time>.+)\]\s' #datetime
'"(?P<method>GET|POST)\s(?P<uri>.+)\s(?P<ver>\w+/.+)"\s(?P<status>\d+)\s' #requested file
'(?P<content_length>\d+)\s"(?P<referrer>.+)"\s' #referrer
'"(?P<user_agent>.+)"' #user agent
)
r = re.match(pat, logline)
r.groupdict()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment