nodejs-logitron
Version:
Powerful logger module for Nodejs/ Nestjs, seamlessly integrating Pino and Winston for flexible logging with easy configuration.
2 lines (1 loc) • 2.03 kB
JavaScript
var L=Object.create;var a=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var x=(r,t)=>{for(var e in t)a(r,e,{get:t[e],enumerable:!0})},f=(r,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of N(t))!I.call(r,n)&&n!==e&&a(r,n,{get:()=>t[n],enumerable:!(o=T(t,n))||o.enumerable});return r};var O=(r,t,e)=>(e=r!=null?L(y(r)):{},f(t||!r||!r.__esModule?a(e,"default",{value:r,enumerable:!0}):e,r)),b=r=>f(a({},"__esModule",{value:!0}),r);var v={};x(v,{PinoService:()=>p});module.exports=b(v);var h=O(require("pino"));var u=require("async_hooks"),l=new u.AsyncLocalStorage;function _(r,t,e,o,...n){let s=new Date().toISOString(),g=l.getStore()?.traceId??"N/A",d=n.find(c=>c&&typeof c=="object")??null,E=o?.name&&typeof o?.time=="number"?`${o.name} ${o.time} ms`:"N/A";return`[${s}] [${r.toUpperCase()}] [${t.toUpperCase()}] [${g}] [${e}] [${d?JSON.stringify(d):"N/A"}] [${E}]`}var i=_;var m="nodejs-logitron";var p=class{constructor(t){this.appName=m;this.logger=(0,h.default)({transport:{target:"pino-pretty",options:{ignore:"level"}},base:null,timestamp:!1,...t}),this.appName=t?.appName??m}infoWithExecutionTime(t,e,...o){this.logWithExecutionTime("info",t,e,...o)}warnWithExecutionTime(t,e,...o){this.logWithExecutionTime("warn",t,e,...o)}errorWithExecutionTime(t,e,...o){this.logWithExecutionTime("error",t,e,...o)}debugWithExecutionTime(t,e,...o){this.logWithExecutionTime("debug",t,e,...o)}info(t,...e){let o=i("info",this.appName,t,void 0,...e);this.logger.info(o)}warn(t,...e){let o=i("warn",this.appName,t,void 0,...e);this.logger.warn(o)}error(t,...e){let o=i("error",this.appName,t,void 0,...e);this.logger.error(o)}debug(t,...e){let o=i("debug",this.appName,t,void 0,...e);this.logger.debug(o)}logWithExecutionTime(t,e,o,...n){let s=(performance.now()-o.start).toFixed(2),g=i(t,this.appName,e,{name:o?.name,time:Number(s)},...n);this.logger[t](g)}};0&&(module.exports={PinoService});
;