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.

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const console_1 = require("console");
  4. var LogLevel;
  5. (function (LogLevel) {
  6. LogLevel[LogLevel["INFO"] = 1] = "INFO";
  7. LogLevel[LogLevel["WARN"] = 2] = "WARN";
  8. LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
  9. })(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
  10. const stderrConsole = new console_1.Console(process.stderr);
  11. const stdoutConsole = new console_1.Console(process.stdout);
  12. const doNothingLogger = (_message) => { };
  13. const makeLoggerFunc = (loaderOptions) => loaderOptions.silent
  14. ? (_whereToLog, _message) => { }
  15. : (whereToLog, message) =>
  16. // tslint:disable-next-line:no-console
  17. console.log.call(whereToLog, message);
  18. const makeExternalLogger = (loaderOptions, logger) => (message) => logger(loaderOptions.logInfoToStdOut ? stdoutConsole : stderrConsole, message);
  19. const makeLogInfo = (loaderOptions, logger, green) => LogLevel[loaderOptions.logLevel] <= LogLevel.INFO
  20. ? (message) => logger(loaderOptions.logInfoToStdOut ? stdoutConsole : stderrConsole, green(message))
  21. : doNothingLogger;
  22. const makeLogError = (loaderOptions, logger, red) => LogLevel[loaderOptions.logLevel] <= LogLevel.ERROR
  23. ? (message) => logger(stderrConsole, red(message))
  24. : doNothingLogger;
  25. const makeLogWarning = (loaderOptions, logger, yellow) => LogLevel[loaderOptions.logLevel] <= LogLevel.WARN
  26. ? (message) => logger(stderrConsole, yellow(message))
  27. : doNothingLogger;
  28. function makeLogger(loaderOptions, colors) {
  29. const logger = makeLoggerFunc(loaderOptions);
  30. return {
  31. log: makeExternalLogger(loaderOptions, logger),
  32. logInfo: makeLogInfo(loaderOptions, logger, colors.green),
  33. logWarning: makeLogWarning(loaderOptions, logger, colors.yellow),
  34. logError: makeLogError(loaderOptions, logger, colors.red)
  35. };
  36. }
  37. exports.makeLogger = makeLogger;