index.js 541 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. var format = require('util').format;
  3. var sparkles = require('sparkles');
  4. var levels = [
  5. 'debug',
  6. 'info',
  7. 'warn',
  8. 'error',
  9. ];
  10. function getLogger(namespace) {
  11. var logger = sparkles(namespace);
  12. levels.forEach(function(level) {
  13. logger[level] = makeLogLevel(logger, level);
  14. });
  15. return logger;
  16. }
  17. function makeLogLevel(self, level) {
  18. return function(msg) {
  19. if (typeof msg === 'string') {
  20. msg = format.apply(null, arguments);
  21. }
  22. self.emit(level, msg);
  23. };
  24. }
  25. module.exports = getLogger;