You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1002 B

4 years ago
  1. const SyncBailHook = require("tapable/lib/SyncBailHook");
  2. const { Logger } = require("./Logger");
  3. const createConsoleLogger = require("./createConsoleLogger");
  4. /** @type {createConsoleLogger.LoggerOptions} */
  5. let currentDefaultLoggerOptions = {
  6. level: "info",
  7. debug: false,
  8. console
  9. };
  10. let currentDefaultLogger = createConsoleLogger(currentDefaultLoggerOptions);
  11. /**
  12. * @param {string} name name of the logger
  13. * @returns {Logger} a logger
  14. */
  15. exports.getLogger = name => {
  16. return new Logger((type, args) => {
  17. if (exports.hooks.log.call(name, type, args) === undefined) {
  18. currentDefaultLogger(name, type, args);
  19. }
  20. });
  21. };
  22. /**
  23. * @param {createConsoleLogger.LoggerOptions} options new options, merge with old options
  24. * @returns {void}
  25. */
  26. exports.configureDefaultLogger = options => {
  27. Object.assign(currentDefaultLoggerOptions, options);
  28. currentDefaultLogger = createConsoleLogger(currentDefaultLoggerOptions);
  29. };
  30. exports.hooks = {
  31. log: new SyncBailHook(["origin", "type", "args"])
  32. };