UNPKG

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.01 kB
"use strict";var m=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var N=(o,t)=>{for(var e in t)m(o,e,{get:t[e],enumerable:!0})},y=(o,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of L(t))!T.call(o,n)&&n!==e&&m(o,n,{get:()=>t[n],enumerable:!(r=E(t,n))||r.enumerable});return o};var I=o=>y(m({},"__esModule",{value:!0}),o);var A={};N(A,{WinstonService:()=>c});module.exports=I(A);var s=require("winston");var u=require("async_hooks"),l=new u.AsyncLocalStorage;function x(o,t,e,r,...n){let a=new Date().toISOString(),g=l.getStore()?.traceId??"N/A",d=n.find(f=>f&&typeof f=="object")??null,h=r?.name&&typeof r?.time=="number"?`${r.name} ${r.time} ms`:"N/A";return`[${a}] [${o.toUpperCase()}] [${t.toUpperCase()}] [${g}] [${e}] [${d?JSON.stringify(d):"N/A"}] [${h}]`}var i=x;var p="nodejs-logitron";var{combine:O,timestamp:b,printf:_,colorize:v}=s.format,c=class{constructor(t){this.appName=p;this.logger=(0,s.createLogger)({transports:[new s.transports.Console],format:O(v({all:!0}),b({format:"YYYY-MM-DDThh:mm:ss"}),_(e=>`[${e.timestamp}] ${e.level}: ${e.message}`)),...t}),this.appName=t?.appName??p}infoWithExecutionTime(t,e,...r){this.logWithExecutionTime("info",t,e,...r)}warnWithExecutionTime(t,e,...r){this.logWithExecutionTime("warn",t,e,...r)}errorWithExecutionTime(t,e,...r){this.logWithExecutionTime("error",t,e,...r)}debugWithExecutionTime(t,e,...r){this.logWithExecutionTime("debug",t,e,...r)}info(t,...e){let r=i("info",this.appName,t,void 0,...e);this.logger.info(r)}warn(t,...e){let r=i("warn",this.appName,t,void 0,...e);this.logger.warn(r)}error(t,...e){let r=i("error",this.appName,t,void 0,...e);this.logger.error(r)}debug(t,...e){let r=i("debug",this.appName,t,void 0,...e);this.logger.debug(r)}logWithExecutionTime(t,e,r,...n){let a=(performance.now()-r.start).toFixed(2),g=i(t,this.appName,e,{name:r?.name,time:Number(a)},...n);this.logger[t](g)}};0&&(module.exports={WinstonService});