Skip to content

Commit

Permalink
allow for only a callback to be passed in
Browse files Browse the repository at this point in the history
  • Loading branch information
bahamas10 committed Nov 4, 2012
1 parent f1bf56c commit 0c82dfb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
11 changes: 11 additions & 0 deletions examples/cb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var http = require('http');
var accesslog = require('../');

http.createServer(function(req, res) {
accesslog(req, res, function(s) {
console.log('> ' + s + ' <');
});
res.end();
}).listen(8000, 'localhost', function() {
console.log('Listening on localhost:8000');
});
15 changes: 11 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
var def_format = ':ip :method :statusCode :url (:deltams)';

module.exports = accesslog;

function accesslog(req, res, format, func) {
format = format || ':ip :method :statusCode :url (:deltams)';
func = func || console.log;
function accesslog(req, res, format, cb) {
if (typeof format === 'function') {
cb = format;
format = null;
}

format = format || def_format;
cb = cb || console.log;

req._received_date = new Date();

Expand All @@ -21,6 +28,6 @@ function accesslog(req, res, format, func) {
.replace(':delta', delta);

// log it
func(s);
cb(s);
};
}

0 comments on commit 0c82dfb

Please sign in to comment.