Permalink
Browse files

improved logging in UnitBrowser

  • Loading branch information...
1 parent 15f3786 commit 479680d581132e5d498eb5a618b8012bf1f7c723 Seth Purcell committed with Chris Osborn Jan 3, 2012
Showing with 15 additions and 13 deletions.
  1. +0 −11 lib/Request.js
  2. +15 −2 testing/rigs/UnitBrowser.js
View
@@ -96,17 +96,6 @@ var Request = Class.extend({
this.params[i] = parts.query[i];
}
}
-
- // log the start of the request
-// this.log('info', "begin", {
-// req: this.id,
-// c: bodyStream && bodyStream.connection && bodyStream.connection.remoteAddress, // client IP
-// m: method.toUpperCase(), // HTTP method
-// u: this.url, // requested URL
-// h: this.getHeader('host'), // host header
-// a: this.getHeader('user-agent'), // user agent
-// r: this.getHeader('referer') // referer
-// });
},
///////////////////////////////////////////////////////////////////////////////
@@ -37,8 +37,9 @@ var ClientResponse = capsela.ClientResponse;
var Q = require('qq');
var StreamUtil = require('capsela-util').StreamUtil;
var Pipe = require('capsela-util').Pipe;
-var Pipe = require('capsela-util').Pipe;
+var Log = require('capsela-util').Log;
var Cookie = capsela.Cookie;
+var Logger = require('capsela-util').Logger;
var baseTemplate =
"<!DOCTYPE html>\
@@ -52,6 +53,8 @@ var baseTemplate =
</html>";
var UnitBrowser = Browser.extend({
+
+ mixin: Logger
},
{
///////////////////////////////////////////////////////////////////////////////
@@ -62,6 +65,8 @@ var UnitBrowser = Browser.extend({
init: function(stage) {
this.compositor = new capsela.stages.Compositor(baseTemplate);
this.compositor.setNext(stage);
+ this.LOG = new Log();
+ this.LOG.watch(this);
this._super();
},
@@ -74,6 +79,8 @@ var UnitBrowser = Browser.extend({
* @return promise
*/
clientDispatch: function(hostname, request) {
+
+ var t = this;
// you know we need this
request.headers.host = hostname;
@@ -86,8 +93,14 @@ var UnitBrowser = Browser.extend({
this.prepRequest(request);
}
- console.log('unit browser: ' + request.method + ' ' +
+ // don't emit - just log directly - to avoid confusing tests that watch the log
+ t.LOG.log(Log.DEBUG, '(unit browser) ' + request.method.toUpperCase() + ' ' +
(request.secure ? 'https://' : 'http://') + hostname + request.path);
+
+ // pass log messages up
+ request.on('log', function(p, m) {
+ t.log(p, m);
+ });
return Q.when(this.compositor.service(request),
function(response) {

0 comments on commit 479680d

Please sign in to comment.