Last active
January 4, 2016 02:09
-
-
Save holys/8553248 to your computer and use it in GitHub Desktop.
python regular pattern for nginx access.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
14.145.146.20 - - [02/Dec/2013:00:01:01 +0800] "GET /api/groups HTTP/1.1" 200 28 "https://qing.wps.cn/" "qing-8.1.17.1 AppleWebKit(2.2.3)" "14.145.146.20" 0.002 - | |
---- | |
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
'$status $bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for" $request_time $upstream_response_time'; |
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
nginx_pattern = re.compile(r"""(?P<clientip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) - - \[(?P<datetime>\d{2}\/[a-z]{3}\/\d{4}:\d{2}:\d{2}:\d{2} (\+|\-)\d{4})\] ((\"(?P<method>\w+?) )(?P<url>.+)(http\/1\.1")) (?P<status>\d{3}) (?P<bytes>\d+) (["](?P<refferer>(\-)|(.+?))["]) (["](?P<useragent>(\-)|(.+?))["]) (["](?P<x_forwarded>(\-)|(.+?))["]) (?P<request_time>(\-)|(.+?)) (?P<upstream_time>(\-)|(.+?))""", re.I) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment