log using grunt
Thomas Aylott committed
Oct 31, 2013 at 19:05 UTC
b7250974099ed36e79c7907e55349d6defd71108
1 file changed
+13
-3
grunt/config/server.js
+13
-3
@@ -4,12 +4,18 @@ module.exports = function(grunt){
4
5
function printMiddleware(req, res, next) {
6
if (req._parsedUrl.pathname != '/print') return next();
7
- grunt[req.query.type || 'log'].writeln(req.query.message);
7
+ if (req.query.message.indexOf('ok') === 0){
8
+ grunt.log.ok(req.query.message);
9
+ } else if (req.query.message.indexOf('not ok') === 0){
10
+ grunt.log.error(req.query.message);
11
+ } else {
12
+ grunt[req.query.type || 'log'].writeln('[%s][%s]', req.headers['user-agent'], Date.now(), req.query.message);
13
+ }
14
res.end(pxlgif);
15
}
16
function testResultLoggerMiddleware(req, res, next) {
17
if (!(req.body && req.body.data)) return next();
12
- grunt.log.writeln(req.body.data);
18
+ grunt.log.writeln('[%s][%s]', req.headers['user-agent'], Date.now(), req.body.data);
19
res.end('Got it, thanks!');
20
}
21
@@ -20,13 +26,17 @@ module.exports = function(grunt){
26
hostname: '*',
27
port: 9999,
28
middleware: function(connect, options) {
29
+ connect.logger.token('user-agent', function(req, res){ return req.headers['user-agent']; });
30
+ connect.logger.token('timestamp', function(req, res){ return Date.now(); });
31
+
32
return [
33
connect.query(),
34
printMiddleware,
35
+
36
+ connect.logger({format:'[:user-agent][:timestamp] :method :url', stream:grunt.verbose}),
37
connect.bodyParser(),
38
testResultLoggerMiddleware,
39
29
- connect.logger(':method :url - :referrer'),
40
connect.static(options.base)
41
];
42
},