UNPKG

irest-app-test

Version:

iRest simulator application tooling and scripts - Backend

2 lines 3.58 kB
"use strict";var _excluded=["label","timestamp","level","message","correlationId","stack","meta"];var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault"),_typeof=require("@babel/runtime/helpers/typeof");Object.defineProperty(exports,"__esModule",{value:!0}),exports.accessLogger=void 0,exports.customFormat=customFormat,exports["default"]=void 0,exports.defaultFormat=defaultFormat,exports.errorLogger=void 0;var _objectWithoutProperties2=_interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")),_winston=_interopRequireWildcard(require("winston")),_expressWinston=_interopRequireDefault(require("express-winston")),_expressCorrelationId=_interopRequireDefault(require("express-correlation-id"));require("winston-daily-rotate-file");function _interopRequireWildcard(a,b){if("function"==typeof WeakMap)var c=new WeakMap,d=new WeakMap;return(_interopRequireWildcard=function(a,b){if(!b&&a&&a.__esModule)return a;var e,g,h={__proto__:null,default:a};if(null===a||"object"!=_typeof(a)&&"function"!=typeof a)return h;if(e=b?d:c){if(e.has(a))return e.get(a);e.set(a,h)}for(var f in a)"default"!=f&&{}.hasOwnProperty.call(a,f)&&((g=(e=Object.defineProperty)&&Object.getOwnPropertyDescriptor(a,f))&&(g.get||g.set)?e(h,f,g):h[f]=a[f]);return h})(a,b)}var printf=_winston.format.printf,combine=_winston.format.combine,timestamp=_winston.format.timestamp,label=_winston.format.label,colorize=_winston.format.colorize,errors=_winston.format.errors,timestampFormat="DD-MM-YY HH:MM:SS";// eslint-disable-next-line no-shadow function customFormat(a){var b=a.label,c=a.timestamp,d=a.level,e=a.message,f=a.correlationId,g=a.stack,h=a.meta,i=(0,_objectWithoutProperties2["default"])(a,_excluded),j="[".concat(b,"] [").concat(c,"] ");return f&&(j+="[x-correlation-id: ".concat(f,"] ")),j+="[level: ".concat(d,"]: ").concat(e," "),h&&(j+="response: ".concat(JSON.stringify(h.res)," "),j+="request body: ".concat(JSON.stringify(h.req)," "),j+="responseTime: ".concat(h.responseTime)),"{}"!==JSON.stringify(i)&&(j+=JSON.stringify(i)),g&&(j+="\n ".concat(g," ")),j+="\n",j}function defaultFormat(a){return combine((0,_winston.format)(function(a){return a.correlationId=_expressCorrelationId["default"].getId(),a})(),errors({stack:!0}),colorize(),combine(colorize({all:!0}),label({label:(null===a||void 0===a?void 0:a.label)||"iREST"}),timestamp({format:timestampFormat}),printf(customFormat)))}var dailyRotateFileTransport=function(a){return new _winston["default"].transports.DailyRotateFile({level:a,filename:"logs/irest-%DATE%.log",datePattern:"YYYY-MM-DD-HH",zippedArchive:!0,maxSize:"20m",maxFiles:"14d",frequency:"24h",format:defaultFormat()})},logger=(0,_winston.createLogger)({transports:[new _winston.transports.Console({level:"error",format:defaultFormat()}),dailyRotateFileTransport("error")],exitOnError:!1,exceptionHandlers:[new _winston.transports.File({filename:"logs/exceptions.log"})]}),headerBlacklist=["cookie","host","sec-ch-ua","sec-ch-ua-mobile","sec-ch-ua-platform","sec-fetch-site","sec-fetch-mode","sec-fetch-dest","accept-encoding","accept-language"],accessLogger=exports.accessLogger=_expressWinston["default"].logger({transports:[new _winston.transports.Console({format:defaultFormat()}),dailyRotateFileTransport("info")],headerBlacklist:headerBlacklist}),errorLogger=exports.errorLogger=_expressWinston["default"].errorLogger({transports:[new _winston["default"].transports.Console({format:defaultFormat(),json:!0}),dailyRotateFileTransport("error")],headerBlacklist:headerBlacklist}),_default=exports["default"]=logger;