github.com/cloudcredo/cloudrocker@v0.0.0-20160108110610-1320f8cc2dfd/sample-apps/node/node_modules/logfmt/examples/restify_pipe_to_stdout2.js (about)

     1  var restify = require('restify');
     2  var through = require('through');
     3  var logfmt  = require('../logfmt');
     4  var split   = require('split');
     5  
     6  var server = restify.createServer({
     7    name: 'logfmt-test-server'
     8  })
     9  
    10  server.use(logfmt.requestLogger());
    11  
    12  server.post('/logs', function(req, res, next){
    13  
    14    var jsonStream = through(function(line){
    15      this.queue(JSON.stringify(line))
    16    }, function(){
    17      this.queue(null)
    18    })
    19  
    20    req.pipe(logfmt.streamParser())
    21       .pipe(jsonStream)
    22       .pipe(process.stdout);
    23  
    24    res.send(201, 'OK')
    25  
    26    return next();
    27  })
    28  
    29  server.listen(3000);