Skip to content

Instantly share code, notes, and snippets.

@shazow
Created May 27, 2013 20:04
Show Gist options
  • Save shazow/5658843 to your computer and use it in GitHub Desktop.
Save shazow/5658843 to your computer and use it in GitHub Desktop.
Parsing nginx-style access logs in Python.
import re
RE_LOG = re.compile(
'(?P<ip>[(\d\.)]+) '
'- - '
'\[(?P<timestamp>.*?)\] '
'"(?P<request>.*?)" '
'(?P<status>\d+) '
'(?P<size>\d+) '
'"(?P<referrer>.*?)" '
'"(?P<user_agent>.*?)"'
)
def parse_line(s):
return RE_LOG.match(s).groupdict()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment