@bymax-one/nest-logger 1.3.1 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +207 -1
- package/README.md +129 -7
- package/dist/server/index.cjs +272 -15
- package/dist/server/index.d.cts +297 -3
- package/dist/server/index.d.ts +297 -3
- package/dist/server/index.mjs +268 -12
- package/dist/shared/index.cjs +1 -0
- package/dist/shared/index.d.cts +1 -0
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.mjs +1 -0
- package/package.json +3 -3
package/dist/server/index.mjs
CHANGED
|
@@ -182,6 +182,7 @@ var RESERVED_LOG_KEYS = Object.freeze({
|
|
|
182
182
|
HTTP_REQUEST_ABORTED: "HTTP_REQUEST_ABORTED",
|
|
183
183
|
HTTP_EXCEPTION_HANDLED: "HTTP_EXCEPTION_HANDLED",
|
|
184
184
|
HTTP_EXCEPTION_UNHANDLED: "HTTP_EXCEPTION_UNHANDLED",
|
|
185
|
+
HTTP_UNEXPECTED_ERROR: "HTTP_UNEXPECTED_ERROR",
|
|
185
186
|
METHOD_EXECUTION: "METHOD_EXECUTION",
|
|
186
187
|
METHOD_SLOW_EXECUTION: "METHOD_SLOW_EXECUTION",
|
|
187
188
|
LOGGER_DESTINATION_INIT_FAILED: "LOGGER_DESTINATION_INIT_FAILED",
|
|
@@ -765,12 +766,26 @@ var HTTP_SERVER_ERROR_MIN = 500;
|
|
|
765
766
|
var UNKNOWN_USER_AGENT = "unknown";
|
|
766
767
|
var RECORDER_ACTIVE = /* @__PURE__ */ Symbol("bymax-one/nest-logger:recorder");
|
|
767
768
|
var RECORDED_ERROR = /* @__PURE__ */ Symbol("bymax-one/nest-logger:error");
|
|
769
|
+
var OWN_REQUEST_ID = /* @__PURE__ */ Symbol("bymax-one/nest-logger:request-id");
|
|
770
|
+
var CORRELATION_OPENED = /* @__PURE__ */ Symbol("bymax-one/nest-logger:correlation");
|
|
768
771
|
function markRecorderActive(req) {
|
|
769
772
|
Reflect.set(req, RECORDER_ACTIVE, true);
|
|
770
773
|
}
|
|
771
774
|
function isRecorderActive(req) {
|
|
772
775
|
return Reflect.get(req, RECORDER_ACTIVE) === true;
|
|
773
776
|
}
|
|
777
|
+
function markCorrelationOpened(req) {
|
|
778
|
+
Reflect.set(req, CORRELATION_OPENED, true);
|
|
779
|
+
}
|
|
780
|
+
function isCorrelationOpened(req) {
|
|
781
|
+
return Reflect.get(req, CORRELATION_OPENED) === true;
|
|
782
|
+
}
|
|
783
|
+
function markOwnRequestId(req, requestId) {
|
|
784
|
+
Reflect.set(req, OWN_REQUEST_ID, requestId);
|
|
785
|
+
}
|
|
786
|
+
function readOwnRequestId(req) {
|
|
787
|
+
return Reflect.get(req, OWN_REQUEST_ID);
|
|
788
|
+
}
|
|
774
789
|
function recordError(req, error) {
|
|
775
790
|
Reflect.set(req, RECORDED_ERROR, { error });
|
|
776
791
|
}
|
|
@@ -788,6 +803,16 @@ function readUserAgent(req) {
|
|
|
788
803
|
return typeof raw === "string" ? raw : UNKNOWN_USER_AGENT;
|
|
789
804
|
}
|
|
790
805
|
|
|
806
|
+
// src/server/utils/matches-exclude-path.util.ts
|
|
807
|
+
function matchesExcludePath(patterns, path2) {
|
|
808
|
+
return patterns.some((pattern) => {
|
|
809
|
+
if (pattern.global || pattern.sticky) {
|
|
810
|
+
pattern.lastIndex = 0;
|
|
811
|
+
}
|
|
812
|
+
return pattern.test(path2);
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
|
|
791
816
|
// src/server/interceptors/http-logging.interceptor.ts
|
|
792
817
|
var HTTP_SUCCESS_MIN = 200;
|
|
793
818
|
var HttpLoggingInterceptor = class {
|
|
@@ -809,7 +834,7 @@ var HttpLoggingInterceptor = class {
|
|
|
809
834
|
* @returns `true` when the path matches a configured exclude pattern.
|
|
810
835
|
*/
|
|
811
836
|
isExcluded(path2) {
|
|
812
|
-
return this.excludePaths
|
|
837
|
+
return matchesExcludePath(this.excludePaths, path2);
|
|
813
838
|
}
|
|
814
839
|
/**
|
|
815
840
|
* Emit the START entry, then attach success/redirect/error logging to the
|
|
@@ -2091,8 +2116,21 @@ var LogContextService = class {
|
|
|
2091
2116
|
* Run `callback` inside a fresh context scope. Every log emitted
|
|
2092
2117
|
* synchronously or asynchronously within the callback inherits `context`.
|
|
2093
2118
|
*
|
|
2119
|
+
* **A nested `run()` REPLACES the enclosing context, it does not extend it.**
|
|
2120
|
+
* The scope starts from `context` alone, so a field an outer scope had set —
|
|
2121
|
+
* a `tenantId` resolved at the edge, say — is absent for the whole inner
|
|
2122
|
+
* scope: nothing throws, `get()` simply returns `undefined`, and the field is
|
|
2123
|
+
* missing from every entry the callback emits. Reach for {@link runMerged}
|
|
2124
|
+
* when the inner scope should extend the outer one.
|
|
2125
|
+
*
|
|
2126
|
+
* Replacement is the deliberate default because the opposite leaks: a
|
|
2127
|
+
* background job started inside a request scope would silently inherit the
|
|
2128
|
+
* caller's `userId` and attribute its entries to a user who never triggered
|
|
2129
|
+
* it. A missing field is visibly missing; an inherited one is wrong while
|
|
2130
|
+
* looking right.
|
|
2131
|
+
*
|
|
2094
2132
|
* @typeParam T - Return type of the callback.
|
|
2095
|
-
* @param context - Initial context bag for the scope.
|
|
2133
|
+
* @param context - Initial context bag for the scope. Becomes the WHOLE scope.
|
|
2096
2134
|
* @param callback - Function executed within the scope.
|
|
2097
2135
|
* @returns Whatever `callback` returns.
|
|
2098
2136
|
* @example
|
|
@@ -2103,6 +2141,35 @@ var LogContextService = class {
|
|
|
2103
2141
|
run(context, callback) {
|
|
2104
2142
|
return this.als.run(this.sanitizeContext(context), callback);
|
|
2105
2143
|
}
|
|
2144
|
+
/**
|
|
2145
|
+
* Run `callback` inside a scope that EXTENDS the enclosing one: the active
|
|
2146
|
+
* context's fields are carried in, and `context` overrides them key by key.
|
|
2147
|
+
*
|
|
2148
|
+
* The explicit counterpart to {@link run}'s replacement semantics, for the
|
|
2149
|
+
* case where an inner scope is genuinely a refinement of the outer — adding a
|
|
2150
|
+
* `userId` once authentication resolved it, without having to restate the
|
|
2151
|
+
* `requestId` the middleware already set.
|
|
2152
|
+
*
|
|
2153
|
+
* Outside any scope there is nothing to merge and this behaves exactly like
|
|
2154
|
+
* {@link run}. Writes inside the new scope never reach the enclosing one: the
|
|
2155
|
+
* merge produces a fresh object, so the outer context is intact after the
|
|
2156
|
+
* callback returns.
|
|
2157
|
+
*
|
|
2158
|
+
* @typeParam T - Return type of the callback.
|
|
2159
|
+
* @param context - Fields to add or override on top of the active context.
|
|
2160
|
+
* @param callback - Function executed within the merged scope.
|
|
2161
|
+
* @returns Whatever `callback` returns.
|
|
2162
|
+
* @example
|
|
2163
|
+
* logContext.run({ requestId: 'r_1' }, () => {
|
|
2164
|
+
* logContext.runMerged({ userId: 'u_1' }, () => {
|
|
2165
|
+
* logContext.get('requestId') // 'r_1' — carried in from the outer scope
|
|
2166
|
+
* })
|
|
2167
|
+
* })
|
|
2168
|
+
*/
|
|
2169
|
+
runMerged(context, callback) {
|
|
2170
|
+
const merged = { ...this.als.getStore(), ...this.sanitizeContext(context) };
|
|
2171
|
+
return this.als.run(merged, callback);
|
|
2172
|
+
}
|
|
2106
2173
|
/**
|
|
2107
2174
|
* Read the active context, or `undefined` when called outside any scope.
|
|
2108
2175
|
*
|
|
@@ -2555,13 +2622,17 @@ var HttpAccessLogMiddleware = class {
|
|
|
2555
2622
|
* @param next - The next handler in the chain.
|
|
2556
2623
|
*/
|
|
2557
2624
|
use(req, res, next) {
|
|
2625
|
+
if (isRecorderActive(req)) {
|
|
2626
|
+
next();
|
|
2627
|
+
return;
|
|
2628
|
+
}
|
|
2558
2629
|
if (!this.isEnabled) {
|
|
2559
2630
|
next();
|
|
2560
2631
|
return;
|
|
2561
2632
|
}
|
|
2562
2633
|
const target = req.originalUrl ?? req.url;
|
|
2563
2634
|
const path2 = stripQueryString(target);
|
|
2564
|
-
if (this.excludePaths
|
|
2635
|
+
if (matchesExcludePath(this.excludePaths, path2)) {
|
|
2565
2636
|
next();
|
|
2566
2637
|
return;
|
|
2567
2638
|
}
|
|
@@ -2657,6 +2728,7 @@ HttpAccessLogMiddleware = __decorateClass([
|
|
|
2657
2728
|
var REQUEST_ID_HEADER = "x-request-id";
|
|
2658
2729
|
var MAX_CORRELATION_ID_LENGTH = 256;
|
|
2659
2730
|
var CORRELATION_ID_CHARSET = /^[A-Za-z0-9._:/+=-]+$/;
|
|
2731
|
+
var INHERITABLE_CONTEXT_KEYS = ["requestId", "tenantId"];
|
|
2660
2732
|
function isAcceptableHeaderValue(value) {
|
|
2661
2733
|
return typeof value === "string" && value.length <= MAX_CORRELATION_ID_LENGTH && CORRELATION_ID_CHARSET.test(value);
|
|
2662
2734
|
}
|
|
@@ -2675,27 +2747,128 @@ var RequestIdMiddleware = class {
|
|
|
2675
2747
|
}
|
|
2676
2748
|
/**
|
|
2677
2749
|
* Echo or mint the `x-request-id`, expose it on the response, and run the
|
|
2678
|
-
* remainder of the request inside
|
|
2750
|
+
* remainder of the request inside its own log-context scope.
|
|
2751
|
+
*
|
|
2752
|
+
* Idempotent: mounting this middleware twice on the same request mints one id,
|
|
2753
|
+
* not two. The request gets its OWN store, started from the enclosing scope's
|
|
2754
|
+
* correlation fields — see {@link INHERITABLE_CONTEXT_KEYS} — and nothing
|
|
2755
|
+
* else, because no other field can be known to belong to this request.
|
|
2756
|
+
*
|
|
2757
|
+
* An enclosing scope's `requestId` is never adopted and never echoed: adoption
|
|
2758
|
+
* reads a value this middleware recorded on the REQUEST, which a scope opened
|
|
2759
|
+
* elsewhere does not have. What the two generation modes do with one, measured
|
|
2760
|
+
* on two requests sharing a long-lived enclosing scope:
|
|
2761
|
+
*
|
|
2762
|
+
* - `shouldGenerateRequestId: true` (default) — each request mints its own
|
|
2763
|
+
* id, the two requests differ, and the enclosing value reaches neither the
|
|
2764
|
+
* header nor the entries.
|
|
2765
|
+
* - `shouldGenerateRequestId: false` with no inbound header — nothing is
|
|
2766
|
+
* minted, so the request scope inherits the enclosing `requestId` and every
|
|
2767
|
+
* request inside that scope logs under it. No header is exposed. That is
|
|
2768
|
+
* the consumer's own scope being inherited, not correlation being reused,
|
|
2769
|
+
* and it is the configuration that says the gateway owns the id.
|
|
2679
2770
|
*
|
|
2680
2771
|
* @param req - The incoming request (Express satisfies the contract).
|
|
2681
2772
|
* @param res - The outgoing response (Express satisfies the contract).
|
|
2682
2773
|
* @param next - The next handler in the chain.
|
|
2683
2774
|
*/
|
|
2684
2775
|
use(req, res, next) {
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2776
|
+
if (isCorrelationOpened(req)) {
|
|
2777
|
+
const ownRequestId = readOwnRequestId(req);
|
|
2778
|
+
if (ownRequestId !== void 0) {
|
|
2779
|
+
this.adoptExistingScope(ownRequestId, req, res);
|
|
2780
|
+
}
|
|
2781
|
+
next();
|
|
2782
|
+
return;
|
|
2783
|
+
}
|
|
2784
|
+
markCorrelationOpened(req);
|
|
2785
|
+
const context = this.inheritableContext();
|
|
2786
|
+
const requestId = this.resolveRequestId(req);
|
|
2689
2787
|
if (requestId !== void 0) {
|
|
2690
2788
|
res.setHeader(REQUEST_ID_HEADER, requestId);
|
|
2691
2789
|
context.requestId = requestId;
|
|
2790
|
+
markOwnRequestId(req, requestId);
|
|
2692
2791
|
}
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2792
|
+
if (context.tenantId === void 0) {
|
|
2793
|
+
const tenantId = this.resolveTenantId(req);
|
|
2794
|
+
if (tenantId !== void 0) {
|
|
2795
|
+
context.tenantId = tenantId;
|
|
2796
|
+
}
|
|
2696
2797
|
}
|
|
2697
2798
|
this.logContext.run(context, () => next());
|
|
2698
2799
|
}
|
|
2800
|
+
/**
|
|
2801
|
+
* The enclosing scope's fields that a request scope may start from.
|
|
2802
|
+
*
|
|
2803
|
+
* Plain `run()` would discard everything the caller had set and a plain merge
|
|
2804
|
+
* would carry identity across requests; {@link INHERITABLE_CONTEXT_KEYS} is
|
|
2805
|
+
* the middle a request scope actually needs.
|
|
2806
|
+
*
|
|
2807
|
+
* @returns A fresh bag, never the enclosing store itself, so writes inside the
|
|
2808
|
+
* request never reach the scope that opened it.
|
|
2809
|
+
*/
|
|
2810
|
+
inheritableContext() {
|
|
2811
|
+
const store = { ...this.logContext.getStore() };
|
|
2812
|
+
const inherited = {};
|
|
2813
|
+
for (const key of INHERITABLE_CONTEXT_KEYS) {
|
|
2814
|
+
const value = Reflect.get(store, key);
|
|
2815
|
+
if (value !== void 0) {
|
|
2816
|
+
Reflect.set(inherited, key, value);
|
|
2817
|
+
}
|
|
2818
|
+
}
|
|
2819
|
+
return inherited;
|
|
2820
|
+
}
|
|
2821
|
+
/**
|
|
2822
|
+
* Second mount on a request that already carries a correlation id: echo the id
|
|
2823
|
+
* onto the response and fill in a tenant the scope does not have yet, without
|
|
2824
|
+
* opening another scope.
|
|
2825
|
+
*
|
|
2826
|
+
* Nothing is minted and nothing already set is overwritten, so a third mount —
|
|
2827
|
+
* or a thirtieth — changes nothing. The response header is written on every
|
|
2828
|
+
* pass because the enclosing scope may have been opened by consumer code that
|
|
2829
|
+
* never exposed it.
|
|
2830
|
+
*
|
|
2831
|
+
* @param requestId - The id already in scope, which wins.
|
|
2832
|
+
* @param req - The incoming request, read for the tenant header.
|
|
2833
|
+
* @param res - The outgoing response, where the effective id is exposed.
|
|
2834
|
+
*/
|
|
2835
|
+
adoptExistingScope(requestId, req, res) {
|
|
2836
|
+
res.setHeader(REQUEST_ID_HEADER, requestId);
|
|
2837
|
+
this.logContext.set("requestId", requestId);
|
|
2838
|
+
if (this.logContext.get("tenantId") === void 0) {
|
|
2839
|
+
const tenantId = this.resolveTenantId(req);
|
|
2840
|
+
if (tenantId !== void 0) {
|
|
2841
|
+
this.logContext.set("tenantId", tenantId);
|
|
2842
|
+
}
|
|
2843
|
+
}
|
|
2844
|
+
}
|
|
2845
|
+
/**
|
|
2846
|
+
* The correlation id for this request: the inbound header when acceptable,
|
|
2847
|
+
* otherwise a fresh UUID — or nothing at all when `shouldGenerateRequestId` is
|
|
2848
|
+
* off and the caller sent none, which leaves correlation to the upstream
|
|
2849
|
+
* gateway.
|
|
2850
|
+
*
|
|
2851
|
+
* @param req - The incoming request.
|
|
2852
|
+
* @returns The id, or `undefined` when none is available and none is minted.
|
|
2853
|
+
*/
|
|
2854
|
+
resolveRequestId(req) {
|
|
2855
|
+
const incoming = Reflect.get(req.headers, REQUEST_ID_HEADER);
|
|
2856
|
+
const fromHeader = isAcceptableHeaderValue(incoming) ? incoming : void 0;
|
|
2857
|
+
return fromHeader ?? (this.shouldGenerateRequestId ? randomUUID() : void 0);
|
|
2858
|
+
}
|
|
2859
|
+
/**
|
|
2860
|
+
* The tenant id carried by the configured header, when it is acceptable.
|
|
2861
|
+
*
|
|
2862
|
+
* Never minted: a tenant is an assertion about who the request belongs to, and
|
|
2863
|
+
* inventing one would be a fabricated claim rather than a correlation aid.
|
|
2864
|
+
*
|
|
2865
|
+
* @param req - The incoming request.
|
|
2866
|
+
* @returns The tenant id, or `undefined`.
|
|
2867
|
+
*/
|
|
2868
|
+
resolveTenantId(req) {
|
|
2869
|
+
const raw = Reflect.get(req.headers, this.tenantIdHeader);
|
|
2870
|
+
return isAcceptableHeaderValue(raw) ? raw : void 0;
|
|
2871
|
+
}
|
|
2699
2872
|
};
|
|
2700
2873
|
RequestIdMiddleware = __decorateClass([
|
|
2701
2874
|
Injectable(),
|
|
@@ -2703,11 +2876,94 @@ RequestIdMiddleware = __decorateClass([
|
|
|
2703
2876
|
__decorateParam(1, Inject(LOGGER_OPTIONS_TOKEN))
|
|
2704
2877
|
], RequestIdMiddleware);
|
|
2705
2878
|
|
|
2879
|
+
// src/server/middlewares/apply-access-log.ts
|
|
2880
|
+
function resolveDependencies(app) {
|
|
2881
|
+
try {
|
|
2882
|
+
return {
|
|
2883
|
+
logger: app.get(PinoLoggerService),
|
|
2884
|
+
logContext: app.get(LogContextService),
|
|
2885
|
+
options: app.get(LOGGER_OPTIONS_TOKEN)
|
|
2886
|
+
};
|
|
2887
|
+
} catch (cause) {
|
|
2888
|
+
throw new Error(
|
|
2889
|
+
"[BymaxLoggerModule] applyAccessLog(app) called but BymaxLoggerModule was not imported",
|
|
2890
|
+
{ cause }
|
|
2891
|
+
);
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
2894
|
+
function applyAccessLog(app) {
|
|
2895
|
+
const { logger, logContext, options } = resolveDependencies(app);
|
|
2896
|
+
const requestId = new RequestIdMiddleware(logContext, options);
|
|
2897
|
+
const accessLog = new HttpAccessLogMiddleware(logger, logContext, options);
|
|
2898
|
+
app.use((req, res, next) => {
|
|
2899
|
+
requestId.use(req, res, () => {
|
|
2900
|
+
accessLog.use(req, res, next);
|
|
2901
|
+
});
|
|
2902
|
+
});
|
|
2903
|
+
}
|
|
2904
|
+
|
|
2706
2905
|
// src/server/middlewares/apply-request-id-middleware.ts
|
|
2707
2906
|
var ALL_ROUTES = "/";
|
|
2708
2907
|
function applyRequestIdMiddleware(consumer, routes = ALL_ROUTES) {
|
|
2709
2908
|
consumer.apply(RequestIdMiddleware, HttpAccessLogMiddleware).forRoutes(routes);
|
|
2710
2909
|
}
|
|
2910
|
+
var PinoUnexpectedErrorSink = class {
|
|
2911
|
+
/**
|
|
2912
|
+
* @param logger - The structured logger the entry is written to. Injected by
|
|
2913
|
+
* token explicitly: the package is bundled without `emitDecoratorMetadata`,
|
|
2914
|
+
* so implicit class-type injection would not resolve.
|
|
2915
|
+
*/
|
|
2916
|
+
constructor(logger) {
|
|
2917
|
+
this.logger = logger;
|
|
2918
|
+
}
|
|
2919
|
+
/**
|
|
2920
|
+
* Write one `error` entry for an unexpected error. Never throws.
|
|
2921
|
+
*
|
|
2922
|
+
* The entry carries `err` (name, message, scrubbed stack, cause chain and own
|
|
2923
|
+
* fields, through the configured `err` serializer), `method`, `route` and,
|
|
2924
|
+
* when present, `correlationId`. It deliberately carries nothing else from
|
|
2925
|
+
* the request: the report has no body, headers or query to leak, and this
|
|
2926
|
+
* method adds none.
|
|
2927
|
+
*
|
|
2928
|
+
* `report.traceId` is not written. The trace mixin already stamps the active
|
|
2929
|
+
* span's trace id under the configured `otel.traceIdField` — the same span
|
|
2930
|
+
* nest-core read it from — and writing it here would override that field and
|
|
2931
|
+
* ignore `otel.shouldAutoInjectTraceContext: false`.
|
|
2932
|
+
*
|
|
2933
|
+
* @param report - The error and its request coordinates, from nest-core.
|
|
2934
|
+
* @example
|
|
2935
|
+
* sink.record({ error: new TypeError('x is undefined'), method: 'GET', route: '/invoices/:id', correlationId: 'req-1' })
|
|
2936
|
+
* // → { level: 'error', logKey: 'HTTP_UNEXPECTED_ERROR', msg: 'x is undefined',
|
|
2937
|
+
* // err: { type: 'TypeError', message: 'x is undefined', stack: '…' },
|
|
2938
|
+
* // method: 'GET', route: '/invoices/:id', correlationId: 'req-1' }
|
|
2939
|
+
*/
|
|
2940
|
+
record(report) {
|
|
2941
|
+
try {
|
|
2942
|
+
const metadata = { method: report.method, route: report.route };
|
|
2943
|
+
if (report.correlationId !== void 0) {
|
|
2944
|
+
metadata["correlationId"] = report.correlationId;
|
|
2945
|
+
}
|
|
2946
|
+
this.logger.errorStructured(
|
|
2947
|
+
RESERVED_LOG_KEYS.HTTP_UNEXPECTED_ERROR,
|
|
2948
|
+
toLoggableError(report.error),
|
|
2949
|
+
void 0,
|
|
2950
|
+
metadata
|
|
2951
|
+
);
|
|
2952
|
+
} catch {
|
|
2953
|
+
}
|
|
2954
|
+
}
|
|
2955
|
+
};
|
|
2956
|
+
PinoUnexpectedErrorSink = __decorateClass([
|
|
2957
|
+
Injectable(),
|
|
2958
|
+
__decorateParam(0, Inject(PinoLoggerService))
|
|
2959
|
+
], PinoUnexpectedErrorSink);
|
|
2960
|
+
function toLoggableError(value) {
|
|
2961
|
+
try {
|
|
2962
|
+
return isErrorLike(value) ? value : sanitizeError(value);
|
|
2963
|
+
} catch {
|
|
2964
|
+
return sanitizeError(value);
|
|
2965
|
+
}
|
|
2966
|
+
}
|
|
2711
2967
|
var INJECT_LOGGER_CONTEXT_METADATA_KEY = "bymax_logger:context";
|
|
2712
2968
|
function InjectLogger(context) {
|
|
2713
2969
|
return (target, propertyKey, parameterIndex) => {
|
|
@@ -2769,4 +3025,4 @@ function LogPerformance(thresholdMs = DEFAULT_THRESHOLD_MS) {
|
|
|
2769
3025
|
// src/shared/constants/log-keys-convention.constants.ts
|
|
2770
3026
|
var LOG_KEYS_CONVENTION_REGEX = /^[A-Z][A-Z0-9_]+_[A-Z][A-Z0-9_]+(_[A-Z][A-Z0-9_]+)?$/;
|
|
2771
3027
|
|
|
2772
|
-
export { BymaxLoggerModule, DEFAULT_REDACT_PATHS, DefaultStdoutDestination, HttpExceptionFilter, HttpLoggingInterceptor, InjectLogger, LOGGER_DESTINATIONS_TOKEN, LOGGER_OPTIONS_TOKEN, LOGGER_PINO_INSTANCE_TOKEN, LOG_CONTEXT_METADATA_KEY, LOG_CONTEXT_TOKEN, LOG_KEYS_CONVENTION_REGEX, LogContext, LogContextService, LogPerformance, PINO_LEVEL_NAMES, PINO_LEVEL_NUMBERS, PinoLoggerService, PrettyDevDestination, RESERVED_LOG_KEYS, RESERVED_LOG_KEYS_NOT_EMITTED, RequestIdMiddleware, applyRequestIdMiddleware };
|
|
3028
|
+
export { BymaxLoggerModule, DEFAULT_REDACT_PATHS, DefaultStdoutDestination, HttpAccessLogMiddleware, HttpExceptionFilter, HttpLoggingInterceptor, InjectLogger, LOGGER_DESTINATIONS_TOKEN, LOGGER_OPTIONS_TOKEN, LOGGER_PINO_INSTANCE_TOKEN, LOG_CONTEXT_METADATA_KEY, LOG_CONTEXT_TOKEN, LOG_KEYS_CONVENTION_REGEX, LogContext, LogContextService, LogPerformance, PINO_LEVEL_NAMES, PINO_LEVEL_NUMBERS, PinoLoggerService, PinoUnexpectedErrorSink, PrettyDevDestination, RESERVED_LOG_KEYS, RESERVED_LOG_KEYS_NOT_EMITTED, RequestIdMiddleware, applyAccessLog, applyRequestIdMiddleware };
|
package/dist/shared/index.cjs
CHANGED
|
@@ -17,6 +17,7 @@ var RESERVED_LOG_KEYS = Object.freeze({
|
|
|
17
17
|
HTTP_REQUEST_ABORTED: "HTTP_REQUEST_ABORTED",
|
|
18
18
|
HTTP_EXCEPTION_HANDLED: "HTTP_EXCEPTION_HANDLED",
|
|
19
19
|
HTTP_EXCEPTION_UNHANDLED: "HTTP_EXCEPTION_UNHANDLED",
|
|
20
|
+
HTTP_UNEXPECTED_ERROR: "HTTP_UNEXPECTED_ERROR",
|
|
20
21
|
METHOD_EXECUTION: "METHOD_EXECUTION",
|
|
21
22
|
METHOD_SLOW_EXECUTION: "METHOD_SLOW_EXECUTION",
|
|
22
23
|
LOGGER_DESTINATION_INIT_FAILED: "LOGGER_DESTINATION_INIT_FAILED",
|
package/dist/shared/index.d.cts
CHANGED
|
@@ -238,6 +238,7 @@ declare const RESERVED_LOG_KEYS: Readonly<{
|
|
|
238
238
|
readonly HTTP_REQUEST_ABORTED: "HTTP_REQUEST_ABORTED";
|
|
239
239
|
readonly HTTP_EXCEPTION_HANDLED: "HTTP_EXCEPTION_HANDLED";
|
|
240
240
|
readonly HTTP_EXCEPTION_UNHANDLED: "HTTP_EXCEPTION_UNHANDLED";
|
|
241
|
+
readonly HTTP_UNEXPECTED_ERROR: "HTTP_UNEXPECTED_ERROR";
|
|
241
242
|
readonly METHOD_EXECUTION: "METHOD_EXECUTION";
|
|
242
243
|
readonly METHOD_SLOW_EXECUTION: "METHOD_SLOW_EXECUTION";
|
|
243
244
|
readonly LOGGER_DESTINATION_INIT_FAILED: "LOGGER_DESTINATION_INIT_FAILED";
|
package/dist/shared/index.d.ts
CHANGED
|
@@ -238,6 +238,7 @@ declare const RESERVED_LOG_KEYS: Readonly<{
|
|
|
238
238
|
readonly HTTP_REQUEST_ABORTED: "HTTP_REQUEST_ABORTED";
|
|
239
239
|
readonly HTTP_EXCEPTION_HANDLED: "HTTP_EXCEPTION_HANDLED";
|
|
240
240
|
readonly HTTP_EXCEPTION_UNHANDLED: "HTTP_EXCEPTION_UNHANDLED";
|
|
241
|
+
readonly HTTP_UNEXPECTED_ERROR: "HTTP_UNEXPECTED_ERROR";
|
|
241
242
|
readonly METHOD_EXECUTION: "METHOD_EXECUTION";
|
|
242
243
|
readonly METHOD_SLOW_EXECUTION: "METHOD_SLOW_EXECUTION";
|
|
243
244
|
readonly LOGGER_DESTINATION_INIT_FAILED: "LOGGER_DESTINATION_INIT_FAILED";
|
package/dist/shared/index.mjs
CHANGED
|
@@ -15,6 +15,7 @@ var RESERVED_LOG_KEYS = Object.freeze({
|
|
|
15
15
|
HTTP_REQUEST_ABORTED: "HTTP_REQUEST_ABORTED",
|
|
16
16
|
HTTP_EXCEPTION_HANDLED: "HTTP_EXCEPTION_HANDLED",
|
|
17
17
|
HTTP_EXCEPTION_UNHANDLED: "HTTP_EXCEPTION_UNHANDLED",
|
|
18
|
+
HTTP_UNEXPECTED_ERROR: "HTTP_UNEXPECTED_ERROR",
|
|
18
19
|
METHOD_EXECUTION: "METHOD_EXECUTION",
|
|
19
20
|
METHOD_SLOW_EXECUTION: "METHOD_SLOW_EXECUTION",
|
|
20
21
|
LOGGER_DESTINATION_INIT_FAILED: "LOGGER_DESTINATION_INIT_FAILED",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bymax-one/nest-logger",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Structured JSON logging for NestJS based on Pino 10, with optional OpenTelemetry correlation.",
|
|
5
5
|
"author": "Bymax One <support@bymax.one>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
"check:mutants": "node scripts/check-mutation-directives.mjs",
|
|
62
62
|
"check:published": "node scripts/check-published-surface.mjs",
|
|
63
63
|
"clean": "rm -rf dist coverage",
|
|
64
|
-
"lint": "eslint src",
|
|
65
|
-
"lint:fix": "eslint src --fix",
|
|
64
|
+
"lint": "eslint src scripts test bench '*.config.ts' '*.config.mjs' '*.config.cjs'",
|
|
65
|
+
"lint:fix": "eslint src scripts test bench '*.config.ts' '*.config.mjs' '*.config.cjs' --fix",
|
|
66
66
|
"mutation": "stryker run",
|
|
67
67
|
"mutation:full": "node -e \"require('node:fs').rmSync('reports/stryker-incremental.json',{force:true,recursive:true})\" && stryker run",
|
|
68
68
|
"mutation:dry-run": "stryker run --dryRunOnly",
|