Skip to content

Instantly share code, notes, and snippets.

@wolf0403
Created March 13, 2014 03:27
Show Gist options
  • Save wolf0403/9521486 to your computer and use it in GitHub Desktop.
Save wolf0403/9521486 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