browser.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. var enabled = require('enabled');
  3. /**
  4. * Bare minimum browser version of diagnostics. It doesn't need fancy pancy
  5. * detection algorithms. The code is only enabled when *you* enable it for
  6. * debugging purposes.
  7. *
  8. * @param {String} name Namespace of the diagnostics instance.
  9. * @returns {Function} The logger.
  10. * @api public
  11. */
  12. module.exports = function factory(name) {
  13. if (!enabled(name)) return function diagnopes() {};
  14. return function diagnostics() {
  15. var args = Array.prototype.slice.call(arguments, 0);
  16. //
  17. // We cannot push a value as first argument of the argument array as
  18. // console's formatting %s, %d only works on the first argument it receives.
  19. // So in order to prepend our namespace we need to override and prefix the
  20. // first argument.
  21. //
  22. args[0] = name +': '+ args[0];
  23. //
  24. // So yea. IE8 doesn't have an apply so we need a work around to puke the
  25. // arguments in place.
  26. //
  27. try { Function.prototype.apply.call(console.log, console, args); }
  28. catch (e) {}
  29. };
  30. };