nestjs-logitron
Version:
Powerful logger module for Nodejs/ Nestjs, seamlessly integrating Pino and Winston for flexible logging with easy configuration.
2 lines (1 loc) • 2.01 kB
JavaScript
var m=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var L=(o,e)=>{for(var t in e)m(o,t,{get:e[t],enumerable:!0})},v=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of N(e))!b.call(o,n)&&n!==t&&m(o,n,{get:()=>e[n],enumerable:!(r=x(e,n))||r.enumerable});return o};var T=o=>v(m({},"__esModule",{value:!0}),o);var I={};L(I,{WinstonService:()=>c});module.exports=T(I);var s=require("winston");var f=require("async_hooks"),l=new f.AsyncLocalStorage;function E(o,e,t,r,...n){let a=new Date().toISOString(),g=l.getStore()?.traceId??"N/A",d=n.find(u=>u&&typeof u=="object")??null,h=r?.name??"N/A",y=typeof r?.time=="number"?`${r.time} ms`:"N/A";return`[${a}] [${o.toUpperCase()}] [${e.toUpperCase()}] [${g}] [${t}] [${d?JSON.stringify(d):"N/A"}] [${h}] [${y}]`}var i=E;var p="nestjs-logitron";var{combine:$,timestamp:w,printf:M,colorize:A}=s.format,c=class{constructor(e){this.appName=p;this.logger=(0,s.createLogger)({transports:[new s.transports.Console],format:$(A({all:!0}),w({format:"YYYY-MM-DDThh:mm:ss"}),M(t=>`[${t.timestamp}] ${t.level}: ${t.message}`)),...e}),this.appName=e?.appName??p}infoWithExecutionTime(e,t,...r){this.logWithExecutionTime("info",e,t,...r)}warnWithExecutionTime(e,t,...r){this.logWithExecutionTime("warn",e,t,...r)}errorWithExecutionTime(e,t,...r){this.logWithExecutionTime("error",e,t,...r)}debugWithExecutionTime(e,t,...r){this.logWithExecutionTime("debug",e,t,...r)}info(e,...t){let r=i("info",this.appName,e,void 0,...t);this.logger.info(r)}warn(e,...t){let r=i("warn",this.appName,e,void 0,...t);this.logger.warn(r)}error(e,...t){let r=i("error",this.appName,e,void 0,...t);this.logger.error(r)}debug(e,...t){let r=i("debug",this.appName,e,void 0,...t);this.logger.debug(r)}logWithExecutionTime(e,t,r,...n){let a=(performance.now()-r.start).toFixed(2),g=i(e,this.appName,t,{name:r?.name,time:Number(a)},...n);this.logger[e](g)}};0&&(module.exports={WinstonService});
;