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.02 kB
JavaScript
import C from"fs";import F from"readline";async function D(P){let{logFilePath:i,page:E,limit:s,logRegex:S=/^\[(.*?)\] \[(.*?)\] \[(.*?)\] \[(.*?)\] \[(.*?)\] \[(.*?)\] \[(.*?)\] \[(.*?)\]$/,level:c,traceId:l,appName:m,message:g,execution:p,searchPayload:u}=P;if(!C.existsSync(i))throw new Error("File not found");let v=C.createReadStream(i,"utf-8"),A=F.createInterface({input:v,crlfDelay:1/0}),f=[],e=0,d=(E-1)*s,I=d+s;for await(let n of A){let t=n.match(S);if(!t)continue;let[,R,w,L,a,y,o,r]=t,h=w?w.toLowerCase():"unknown",x=o&&o!=="N/A"?JSON.parse(o):"",N=r&&r!=="N/A"?r:"";c&&h!==c.toLowerCase()||l&&a!==l||m&&L?.toLowerCase()!==m.toLowerCase()||g&&!y?.toLowerCase().includes(g.toLowerCase())||p&&N!==p||u&&o!=="N/A"&&!JSON.stringify(x).toLowerCase().includes(u.toLowerCase())||(e>=d&&e<I&&f.push({id:a&&a.length>0?a:"N/A",timestamp:R,level:h,appName:L,message:y,payload:x,execution:N}),e++)}return{total:e,data:f.sort((n,t)=>new Date(t.timestamp).getTime()-new Date(n.timestamp).getTime())}}export{D as parseLogFile};