console.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. Object.defineProperty(exports, '__esModule', { value: true });
  2. const logger = require('../logger.js');
  3. const object = require('../object.js');
  4. const worldwide = require('../worldwide.js');
  5. const _handlers = require('./_handlers.js');
  6. /**
  7. * Add an instrumentation handler for when a console.xxx method is called.
  8. *
  9. * Use at your own risk, this might break without changelog notice, only used internally.
  10. * @hidden
  11. */
  12. function addConsoleInstrumentationHandler(handler) {
  13. const type = 'console';
  14. _handlers.addHandler(type, handler);
  15. _handlers.maybeInstrument(type, instrumentConsole);
  16. }
  17. function instrumentConsole() {
  18. if (!('console' in worldwide.GLOBAL_OBJ)) {
  19. return;
  20. }
  21. logger.CONSOLE_LEVELS.forEach(function (level) {
  22. if (!(level in worldwide.GLOBAL_OBJ.console)) {
  23. return;
  24. }
  25. object.fill(worldwide.GLOBAL_OBJ.console, level, function (originalConsoleMethod) {
  26. logger.originalConsoleMethods[level] = originalConsoleMethod;
  27. return function (...args) {
  28. const handlerData = { args, level };
  29. _handlers.triggerHandlers('console', handlerData);
  30. const log = logger.originalConsoleMethods[level];
  31. log && log.apply(worldwide.GLOBAL_OBJ.console, args);
  32. };
  33. });
  34. });
  35. }
  36. exports.addConsoleInstrumentationHandler = addConsoleInstrumentationHandler;
  37. //# sourceMappingURL=console.js.map