Skip to content

Instantly share code, notes, and snippets.

@CN6033
Last active August 31, 2015 01:43
Show Gist options
  • Save CN6033/529c50619880a1ce9dd3 to your computer and use it in GitHub Desktop.
Save CN6033/529c50619880a1ce9dd3 to your computer and use it in GitHub Desktop.
__author__ = "Huang Shitao"
__email__ = "huangshitao@outlook.com"
__license__ = "None"
import re
import sys
def process_log(log):
pattern = (r''
'([^ ]*) - ' #remote_addr
'([^ ]*) ' #remote_user
'\[([^\]]*)\] ' #time_local
'\[([^\]]*)\] ' #request_time
'\[([^\]]*)\] ' #request_length
'"([^"]*)" ' #request
'([^ ]*) ' #status
'([^ ]*) ' #body_bytes_sent
'"([^"]*)" ' #http_referer
'"([^"]*)" ' #http_user_agent
'"([^"]*)" ' #http_x_forwarded_for
'"([^"]*)" ' #cookie_JSESSIONID
'"([^"]*)" ' #http_authorization
'"([^"]*)" ' #upstream_addr
'\[([^\]]*)\]' #upstream_response_time
)
match = re.findall(pattern, log)
return match[0]
if __name__ == '__main__':
for line in sys.stdin:
process_log(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment