Skip to content

Commit

Permalink
Merge branch 'master' of github.com:senchalabs/connect
Browse files Browse the repository at this point in the history
  • Loading branch information
creationix committed Aug 13, 2010
2 parents 66a9c66 + 0c84a33 commit f4a4c42
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
4 changes: 4 additions & 0 deletions History.md
Expand Up @@ -2,6 +2,9 @@
1.0.0 / 2010-07-21
==================

* Added connect.middleware to expose the middleware getters
* Added `buffer` option to _logger_ for performance increase
* Added _favicon_ middleware for serving your own favicon or the connect default
* Added option support to _staticProvider_, can now pass _root_ and _lifetime_.
* Added; mounted `Server` instances now have the `route` property exposed for reflection
* Added support for callback as first arg to `Server#use()`
Expand All @@ -24,6 +27,7 @@
* Fixed _less_ support in _compiler_
* Fixed bug preventing proper bubbling of exceptions in mounted servers
* Fixed bug in `Server#use()` preventing `Server` instances as the first arg
* Fixed **ENOENT** special case, is now treated as any other exception
* Fixed spark env support

0.2.1 / 2010-07-09
Expand Down
6 changes: 6 additions & 0 deletions docs/logger.md
Expand Up @@ -6,6 +6,12 @@ The _logger_ middleware provides common log format support, as well as custom fo
connect.logger(),
);

The logger also has built in buffering support to increase performance. When the `buffer` option is set to `true` it defaults to 1000 milliseconds, however you can specify your own duration. When using the `buffer` option log lines are not written to the stream immediately, they are buffered in an array, and flushed periodically.

connect.createServer(
connect.logger({ buffer: 2000 })
);

A custom format can also be passed:

connect.createServer(
Expand Down
2 changes: 1 addition & 1 deletion examples/router/app.js
Expand Up @@ -58,7 +58,7 @@ function main(app){
var connect = require('./../../lib/connect');

var server = connect.createServer(
connect.logger()
connect.logger({ buffer: true })
);

server.use("/users/", connect.router(user));
Expand Down
4 changes: 2 additions & 2 deletions lib/connect/middleware/conditionalGet.js
Expand Up @@ -32,7 +32,7 @@ module.exports = function conditionalGet(){

res.writeHead = function (code, headers) {
var lastModified = headers["Last-Modified"],
etag = headers["Etag"];
etag = headers["ETag"];
lastModified = lastModified && Date.parse(lastModified).valueOf();

// If there is no match, then move on.
Expand Down Expand Up @@ -68,4 +68,4 @@ module.exports = function conditionalGet(){

next();
};
};
};
36 changes: 35 additions & 1 deletion lib/connect/middleware/logger.js
Expand Up @@ -5,13 +5,30 @@
* MIT Licensed
*/

/**
* Log buffer.
*
* @type Array
*/

var buf = [];

/**
* Default log buffer duration.
*
* @type Number
*/

var defaultBufferDuration = 1000;

/**
* Log requests with the given `options`.
*
* Options:
*
* - `format` Format string, see below for tokens
* - `stream` Output stream, defaults to _stdout_
* - `buffer` Buffer duration, defaults to 1000ms when _true_
*
* Tokens:
*
Expand All @@ -35,7 +52,24 @@ module.exports = function logger(options) {
options = options || {};

var fmt = process.connectEnv.logFormat || options.format,
stream = options.stream || process.stdout;
stream = options.stream || process.stdout,
buffer = options.buffer;

// Buffering support
if (buffer) {
var realStream = stream;
setInterval(function(){
if (buf.length) {
realStream.write(buf.join(''), 'ascii');
buf.length = 0;
}
}, typeof buffer === 'number' ? buffer : defaultBufferDuration);
stream = {
write: function(str){
buf.push(str);
}
};
}

return function logger(req, res, next) {
var start = +new Date,
Expand Down

0 comments on commit f4a4c42

Please sign in to comment.