log using grunt

This commit is contained in:
Thomas Aylott committed 2013-11-06 15:30:51 -05:00
1 parent 772af52f4a
commit b725097409
1 file changed
+13 -3
+13 -3
View File
@@ -4,12 +4,18 @@ module.exports = function(grunt){
function printMiddleware(req, res, next) {
if (req._parsedUrl.pathname != '/print') return next();
grunt[req.query.type || 'log'].writeln(req.query.message);
if (req.query.message.indexOf('ok') === 0){
grunt.log.ok(req.query.message);
} else if (req.query.message.indexOf('not ok') === 0){
grunt.log.error(req.query.message);
} else {
grunt[req.query.type || 'log'].writeln('[%s][%s]', req.headers['user-agent'], Date.now(), req.query.message);
}
res.end(pxlgif);
}
function testResultLoggerMiddleware(req, res, next) {
if (!(req.body && req.body.data)) return next();
grunt.log.writeln(req.body.data);
grunt.log.writeln('[%s][%s]', req.headers['user-agent'], Date.now(), req.body.data);
res.end('Got it, thanks!');
}
@@ -20,13 +26,17 @@ module.exports = function(grunt){
hostname: '*',
port: 9999,
middleware: function(connect, options) {
connect.logger.token('user-agent', function(req, res){ return req.headers['user-agent']; });
connect.logger.token('timestamp', function(req, res){ return Date.now(); });
return [
connect.query(),
printMiddleware,
connect.logger({format:'[:user-agent][:timestamp] :method :url', stream:grunt.verbose}),
connect.bodyParser(),
testResultLoggerMiddleware,
connect.logger(':method :url - :referrer'),
connect.static(options.base)
];
},