nginx-log-parser
v0.0.4
Published
Downloads
112
Readme
nginx-log-parser
$ npm install nginx-log-parser
var source = '$http_client_ip $remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$upstream_response_time" $request_time $host $upstream_status $upstream_addr $http_deviceType $http_productId $http_appVersion $http_market';
var parser = require("nginx-log-parser")(source);
var log = '- - - [25/Feb/2016:03:28:25 +0800] "GET /regions/7 HTTP/1.1" 200 6385 "-" "xxx/4.1.2 (iPhone; iOS 9.2.1; Scale/3.00)" "0.006" 0.006 api.xxx.com 200 10.0.0.38:5101';
var data = parser(log);
console.log(data);
<!--
{ http_client_ip: '-',
remote_addr: '-',
remote_user: '-',
time_local: '[25/Feb/2016:03:28:25+0800]',
request: '"GET /regions/7 HTTP/1.1"',
status: '200',
body_bytes_sent: '6385',
http_referer: '"-"',
http_user_agent: '"xxx/4.1.2 (iPhone; iOS 9.2.1; Scale/3.00)"',
upstream_response_time: '"0.006"',
request_time: '0.006',
host: 'api.xxx.com',
upstream_status: '200',
upstream_addr: '10.0.0.38:5101' } -->