index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. 'use strict';
  2. /*
  3. Initial code from https://github.com/gulpjs/gulp-util/blob/v3.0.6/lib/log.js
  4. */
  5. var chalk = require('chalk');
  6. var timestamp = require('time-stamp');
  7. function getTimestamp(){
  8. return '['+chalk.grey(timestamp('HH:mm:ss'))+']';
  9. }
  10. function log(){
  11. var time = getTimestamp();
  12. process.stdout.write(time + ' ');
  13. console.log.apply(console, arguments);
  14. return this;
  15. }
  16. function info(){
  17. var time = getTimestamp();
  18. process.stdout.write(time + ' ');
  19. console.info.apply(console, arguments);
  20. return this;
  21. }
  22. function dir(){
  23. var time = getTimestamp();
  24. process.stdout.write(time + ' ');
  25. console.dir.apply(console, arguments);
  26. return this;
  27. }
  28. function warn(){
  29. var time = getTimestamp();
  30. process.stderr.write(time + ' ');
  31. console.warn.apply(console, arguments);
  32. return this;
  33. }
  34. function error(){
  35. var time = getTimestamp();
  36. process.stderr.write(time + ' ');
  37. console.error.apply(console, arguments);
  38. return this;
  39. }
  40. module.exports = log;
  41. module.exports.info = info;
  42. module.exports.dir = dir;
  43. module.exports.warn = warn;
  44. module.exports.error = error;