test.logger.js 910 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Module dependencies.
  3. */
  4. var cluster = require('../')
  5. , http = require('http')
  6. , fs = require('fs');
  7. require('./common');
  8. var server = http.createServer(function(req, res){
  9. console.log('%s %s', req.method, req.url);
  10. res.writeHead(200);
  11. res.end('Hello World');
  12. });
  13. cluster = cluster(server)
  14. .set('workers', 1)
  15. .use(cluster.logger())
  16. .listen(3000);
  17. cluster.on('listening', function(){
  18. http.get({ host: 'localhost', port: 3000 }, function(res){
  19. res.on('end', function(){
  20. var files = fs.readdirSync(__dirname + '/logs');
  21. files.should.have.length(5);
  22. files.should.contain('master.log');
  23. files.should.contain('workers.access.log');
  24. files.should.contain('workers.error.log');
  25. fs.readFile(__dirname + '/logs/workers.access.log', 'ascii', function(err, str){
  26. str.should.match(/^GET \//);
  27. cluster.close();
  28. });
  29. });
  30. });
  31. });