runtime.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const { SyncBailHook } = require("tapable");
  7. const { Logger } = require("./Logger");
  8. const createConsoleLogger = require("./createConsoleLogger");
  9. /** @type {createConsoleLogger.LoggerOptions} */
  10. let currentDefaultLoggerOptions = {
  11. level: "info",
  12. debug: false,
  13. console
  14. };
  15. let currentDefaultLogger = createConsoleLogger(currentDefaultLoggerOptions);
  16. /**
  17. * @param {string} name name of the logger
  18. * @returns {Logger} a logger
  19. */
  20. exports.getLogger = name => {
  21. return new Logger(
  22. (type, args) => {
  23. if (exports.hooks.log.call(name, type, args) === undefined) {
  24. currentDefaultLogger(name, type, args);
  25. }
  26. },
  27. childName => exports.getLogger(`${name}/${childName}`)
  28. );
  29. };
  30. /**
  31. * @param {createConsoleLogger.LoggerOptions} options new options, merge with old options
  32. * @returns {void}
  33. */
  34. exports.configureDefaultLogger = options => {
  35. Object.assign(currentDefaultLoggerOptions, options);
  36. currentDefaultLogger = createConsoleLogger(currentDefaultLoggerOptions);
  37. };
  38. exports.hooks = {
  39. log: new SyncBailHook(["origin", "type", "args"])
  40. };