flush-on-exit.js 715 B

123456789101112131415161718192021222324252627
  1. /**
  2. * run this, then "ab -c 10 -n 100 localhost:4444/" to test (in
  3. * another shell)
  4. */
  5. var log4js = require('../lib/log4js');
  6. log4js.configure({
  7. appenders: [
  8. { type: 'file', filename: 'cheese.log', category: 'cheese' },
  9. { type: 'console'}
  10. ]
  11. });
  12. var logger = log4js.getLogger('cheese');
  13. logger.setLevel('INFO');
  14. var http=require('http');
  15. var server = http.createServer(function(request, response){
  16. response.writeHead(200, {'Content-Type': 'text/plain'});
  17. var rd = Math.random() * 50;
  18. logger.info("hello " + rd);
  19. response.write('hello ');
  20. if (Math.floor(rd) == 30){
  21. log4js.shutdown(function() { process.exit(1); });
  22. }
  23. response.end();
  24. }).listen(4444);