Forked from shenfeng/nginx_access_log_parser.py
Last active
November 21, 2017 09:04
-
-
Save randy-ran/9b6cc1c8fff016189a62abce14dce276 to your computer and use it in GitHub Desktop.
[parse nginx access log in python] parse nginx access log in python #log
This file contains 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
def seg_access_log(line): | |
delimiters = {'[': ']', '"': '"'} | |
idx, start, count, delimiter, results = 0, 0, len(line), ' ', [] | |
while 1: | |
idx = line.find(delimiter, start) | |
delimiter = ' ' # reset | |
if idx < 0: | |
break | |
if start < idx: | |
results.append(line[start:idx]) | |
start = idx + 1 | |
# if idx != count - 1 and line[idx + 1] in delimiters: | |
if line[idx + 1] in delimiters: | |
delimiter = delimiters[line[idx + 1]] | |
start += 1 | |
if start < count: | |
results.append(line[start:].rstrip()) | |
return results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment