php - How to convert nginx log regular format into apache log format
大家讲道理
大家讲道理 2017-05-16 13:13:53
0
1
391

nginx log format

log_format  access  '$remote_addr - [$time_local] "$request" '
             '$status $body_bytes_sent $request_time "$http_referer" '
             '"$http_user_agent" - $http_x_forwarded_for';

The following is the log regular extraction format of nginx

log_pattern = r'^(?P<remote_addr>.*?) - \[(?P<time_local>.*?)\] "(?P<request>.*?)"' \
              r' (?P<status>.*?) (?P<body_bytes_sent>.*?) (?P<request_time>.*?)' \
              r' "(?P<http_referer>.*?)" "(?P<http_user_agent>.*?)" - (?P<http_x_forwarded_for>.*)$'

request_uri_pattern = r'^(?P<request_method>(GET|POST|HEAD|DELETE)?) (?P<request_uri>.*?) (?P<server_protocol>HTTP.*)$'

My Apache log format is as follows:

123.125.71.55 - - [14/Apr/2017:00:00:15 +0800] "GET /article/511615 HTTP/1.1" 200 11238
111.206.221.100 - - [14/Apr/2017:00:00:16 +0800] "POST /baidutj/tj HTTP/1.1" 302 -

How do I change the above regular rules into regular ones that I can use?

I have been trying for a long time but I keep getting errors,

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
伊谢尔伦
log_pattern = (r'^(?P<remote_addr>\S+) - - \[(?P<time_local>[^]]+)\] "(?P<request>.*?)"'
              ' (?P<status>\d+) (?P<body_bytes_sent>\d+)')
request_uri_pattern = r'"(?P<request_method>(?:GET|POST|HEAD|DELETE)?) (?P<request_uri>\S*) (?P<server_protocol>HTTP\S*?")'
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template