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