Logger.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.Logger = void 0;
  7. const pino_1 = __importDefault(require("pino"));
  8. const pino_http_1 = __importDefault(require("pino-http"));
  9. const MessageTypes_1 = require("./MessageTypes");
  10. const http_1 = require("../http");
  11. class Logger {
  12. constructor() {
  13. this.logger = (0, pino_1.default)({
  14. transport: {
  15. target: 'pino-pretty',
  16. options: {
  17. translateTime: 'yyyy-mm-dd HH:MM:ss.l o',
  18. }
  19. }
  20. });
  21. this.httpLogger = (0, pino_http_1.default)({
  22. logger: this.logger,
  23. customLogLevel: (req, res, err) => {
  24. if (res.statusCode >= http_1.StatusCodes.INTERNAL_SERVER_ERROR || err)
  25. return MessageTypes_1.MessageTypes.ERROR;
  26. if (res.statusCode >= http_1.StatusCodes.BAD_REQUEST)
  27. return MessageTypes_1.MessageTypes.WARNING;
  28. return MessageTypes_1.MessageTypes.INFO;
  29. },
  30. });
  31. }
  32. getLogger() {
  33. return this.logger;
  34. }
  35. getHttpLogger() {
  36. return this.httpLogger;
  37. }
  38. }
  39. exports.Logger = Logger;
  40. //# sourceMappingURL=Logger.js.map