nodejs-logitron
Version:
Powerful logger module for Nodejs/ Nestjs, seamlessly integrating Pino and Winston for flexible logging with easy configuration.
2 lines (1 loc) • 499 B
JavaScript
import{v4 as g}from"uuid";import{AsyncLocalStorage as m}from"async_hooks";var a=new m;function n(t,o){a.run({traceId:t},o)}var i="x-trace-id";var r=class r{static getTraceIdField(){return r.traceIdField}static setTraceIdField(o){r.traceIdField=o}static getTraceId(){return a.getStore()?.traceId??null}};r.traceIdField=i;var e=r;function A(t,o,s){let c=t?.headers?.[e.getTraceIdField()]??t?.body?.[e.getTraceIdField()]??t?.query?.[e.getTraceIdField()]??g();n(c,()=>s())}export{A as traceMiddleware};