nestjs-logitron
Version:
Powerful logger module for Nodejs/ Nestjs, seamlessly integrating Pino and Winston for flexible logging with easy configuration.
2 lines (1 loc) • 1.39 kB
JavaScript
import y from"pino";import{AsyncLocalStorage as l}from"async_hooks";var c=new l;function h(g,t,r,e,...n){let i=new Date().toISOString(),a=c.getStore()?.traceId??"N/A",m=n.find(p=>p&&typeof p=="object")??null,f=e?.name??"N/A",u=typeof e?.time=="number"?`${e.time} ms`:"N/A";return`[${i}] [${g.toUpperCase()}] [${t.toUpperCase()}] [${a}] [${r}] [${m?JSON.stringify(m):"N/A"}] [${f}] [${u}]`}var o=h;var s="nestjs-logitron";var d=class{constructor(t){this.appName=s;this.logger=y({transport:{target:"pino-pretty",options:{ignore:"level"}},base:null,timestamp:!1,...t}),this.appName=t?.appName??s}infoWithExecutionTime(t,r,...e){this.logWithExecutionTime("info",t,r,...e)}warnWithExecutionTime(t,r,...e){this.logWithExecutionTime("warn",t,r,...e)}errorWithExecutionTime(t,r,...e){this.logWithExecutionTime("error",t,r,...e)}debugWithExecutionTime(t,r,...e){this.logWithExecutionTime("debug",t,r,...e)}info(t,...r){let e=o("info",this.appName,t,void 0,...r);this.logger.info(e)}warn(t,...r){let e=o("warn",this.appName,t,void 0,...r);this.logger.warn(e)}error(t,...r){let e=o("error",this.appName,t,void 0,...r);this.logger.error(e)}debug(t,...r){let e=o("debug",this.appName,t,void 0,...r);this.logger.debug(e)}logWithExecutionTime(t,r,e,...n){let i=(performance.now()-e.start).toFixed(2),a=o(t,this.appName,r,{name:e?.name,time:Number(i)},...n);this.logger[t](a)}};export{d as PinoService};