logger.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.makeLogger = void 0;
  4. var console_1 = require("console");
  5. var LogLevel;
  6. (function (LogLevel) {
  7. LogLevel[LogLevel["INFO"] = 1] = "INFO";
  8. LogLevel[LogLevel["WARN"] = 2] = "WARN";
  9. LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
  10. })(LogLevel || (LogLevel = {}));
  11. var stderrConsole = new console_1.Console(process.stderr);
  12. var stdoutConsole = new console_1.Console(process.stdout);
  13. var doNothingLogger = function (_message) {
  14. /* Do nothing */
  15. };
  16. var makeLoggerFunc = function (options) {
  17. return options.silent
  18. ? function (_whereToLog, _message) {
  19. /* Do nothing */
  20. }
  21. : function (whereToLog, message) { return whereToLog.log(message); };
  22. };
  23. var makeExternalLogger = function (loaderOptions, logger) { return function (message) {
  24. return logger(loaderOptions.logInfoToStdOut ? stdoutConsole : stderrConsole, message);
  25. }; };
  26. var makeLogInfo = function (options, logger, green) {
  27. return LogLevel[options.logLevel] <= LogLevel.INFO
  28. ? function (message) {
  29. return logger(options.logInfoToStdOut ? stdoutConsole : stderrConsole, green(message));
  30. }
  31. : doNothingLogger;
  32. };
  33. var makeLogError = function (options, logger, red) {
  34. return LogLevel[options.logLevel] <= LogLevel.ERROR
  35. ? function (message) { return logger(stderrConsole, red(message)); }
  36. : doNothingLogger;
  37. };
  38. var makeLogWarning = function (options, logger, yellow) {
  39. return LogLevel[options.logLevel] <= LogLevel.WARN
  40. ? function (message) { return logger(stderrConsole, yellow(message)); }
  41. : doNothingLogger;
  42. };
  43. function makeLogger(options, colors) {
  44. var logger = makeLoggerFunc(options);
  45. return {
  46. log: makeExternalLogger(options, logger),
  47. logInfo: makeLogInfo(options, logger, colors.green),
  48. logWarning: makeLogWarning(options, logger, colors.yellow),
  49. logError: makeLogError(options, logger, colors.red),
  50. };
  51. }
  52. exports.makeLogger = makeLogger;
  53. //# sourceMappingURL=logger.js.map