我正在尝试从 nginx 日志文件中解析以下格式:
10.0.0.1 [02/Oct/2012:10:21:46 +0000] GET /api/123/test.json?stop=2012-09-29 502 0
我的python脚本:
#!/usr/bin/env python
f = file('slow-queries.txt', 'r')
# iterate over the lines in the file
for line in f:
# split the line into a list of column values
columns = line.split(' ')
# clean any whitespace off the items
# columns = [col.strip() for col in columns]
# ensure the column has at least one value before printing
if columns:
print "first =>", columns[0] # print the first column
print "second =>", columns[1]
基本上我想要从日志文件中得到的只是发送的查询,所以在上面的例子中,我希望提取/api/123/test.json?stop=2012-09-29
我的脚本似乎没有这样做,我做错了什么?