access-log
Advanced tools
Comparing version 0.0.1 to 0.1.0
var http = require('http'); | ||
var accesslog = require('../'); | ||
var format = 'url=":url" method=":method" statusCode=":statusCode" time=":time"'; | ||
var format = 'url=":url" method=":method" statusCode=":statusCode" delta=":delta" ip=":ip"'; | ||
@@ -6,0 +6,0 @@ http.createServer(function(req, res) { |
module.exports = accesslog; | ||
function accesslog(req, res, format, func) { | ||
format = format || ':method :statusCode :url (:timems)'; | ||
format = format || ':ip :method :statusCode :url (:deltams)'; | ||
func = func || console.log; | ||
@@ -15,2 +15,3 @@ | ||
var delta = new Date() - req._received_date; | ||
var s = format | ||
@@ -20,3 +21,4 @@ .replace(':method', req.method) | ||
.replace(':url', req.url) | ||
.replace(':time', new Date() - req._received_date); | ||
.replace(':ip', req.connection.remoteAddress) | ||
.replace(':delta', delta); | ||
@@ -23,0 +25,0 @@ // log it |
{ | ||
"name": "access-log", | ||
"description": "Add simple access logs to any http or https server", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"author": "Dave Eddy <dave@daveeddy.com> (http://www.daveeddy.com)", | ||
@@ -6,0 +6,0 @@ "contributors": [], |
@@ -23,5 +23,5 @@ access-log | ||
``` | ||
GET 200 /testing (0ms) | ||
GET 200 /index.html (0ms) | ||
GET 200 /projects (0ms) | ||
127.0.0.1 GET 200 /testing (0ms) | ||
127.0.0.1 GET 200 /index.html (0ms) | ||
127.0.0.1 GET 200 /projects (0ms) | ||
``` | ||
@@ -39,3 +39,3 @@ | ||
``` | ||
:method :statusCode :url (:timems) | ||
:ip :method :statusCode :url (:deltams) | ||
``` | ||
@@ -46,3 +46,4 @@ | ||
- `:url` - The requested URL | ||
- `:time` - The latency from request to response in ms | ||
- `:delta` - The latency from request to response in ms | ||
- `:ip` - The remote IP | ||
@@ -58,3 +59,3 @@ #### function | ||
``` js | ||
var format = 'url=":url" method=":method" statusCode=":statusCode" time=":time"'; | ||
var format = 'url=":url" method=":method" statusCode=":statusCode" delta=":delta" ip=":ip"'; | ||
@@ -69,5 +70,5 @@ accesslog(req, res, format, function(s) { | ||
``` | ||
url="/projects" method="GET" statusCode="200" time="0" | ||
url="/testing" method="GET" statusCode="200" time="1" | ||
url="/index.html" method="GET" statusCode="200" time="0" | ||
url="/projects" method="GET" statusCode="200" delta="0" ip="127.0.0.1" | ||
url="/testing" method="GET" statusCode="200" delta="1" ip="127.0.0.1" | ||
url="/index.html" method="GET" statusCode="200" delta="0" ip="127.0.0.1" | ||
``` | ||
@@ -74,0 +75,0 @@ |
3519
40
87