Created
May 27, 2013 20:04
-
-
Save shazow/5658843 to your computer and use it in GitHub Desktop.
Parsing nginx-style access logs in Python.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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