@lark-apaas/nestjs-logger 1.0.2 → 1.0.3-alpha.0
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/LICENSE +13 -0
- package/dist/index.cjs +86 -121
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -20
- package/dist/index.d.ts +4 -20
- package/dist/index.js +75 -110
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,30 +1,14 @@
|
|
|
1
1
|
import { LoggerService, LogLevel, NestMiddleware } from '@nestjs/common';
|
|
2
2
|
import { Logger } from 'pino';
|
|
3
|
+
import { RequestContextService, ObservableService } from '@lark-apaas/nestjs-common';
|
|
3
4
|
import { Request, Response, NextFunction } from 'express';
|
|
4
5
|
|
|
5
|
-
interface RequestContextState {
|
|
6
|
-
requestId: string;
|
|
7
|
-
path?: string;
|
|
8
|
-
method?: string;
|
|
9
|
-
userId?: string;
|
|
10
|
-
appId?: string;
|
|
11
|
-
tenantId?: string;
|
|
12
|
-
ip?: string;
|
|
13
|
-
[key: string]: unknown;
|
|
14
|
-
}
|
|
15
|
-
declare class RequestContextService {
|
|
16
|
-
private readonly storage;
|
|
17
|
-
run<T>(context: RequestContextState, callback: () => T): T;
|
|
18
|
-
setContext(partial: Partial<RequestContextState>): void;
|
|
19
|
-
getContext(): RequestContextState | undefined;
|
|
20
|
-
get<K extends keyof RequestContextState>(key: K): RequestContextState[K] | undefined;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
6
|
declare abstract class BasePinoLogger implements LoggerService {
|
|
24
7
|
protected readonly logger: Logger;
|
|
25
8
|
protected readonly contextStore: RequestContextService;
|
|
9
|
+
protected readonly observableService: ObservableService;
|
|
26
10
|
private readonly levelState;
|
|
27
|
-
constructor(logger: Logger, contextStore: RequestContextService);
|
|
11
|
+
constructor(logger: Logger, contextStore: RequestContextService, observableService: ObservableService);
|
|
28
12
|
setLogLevels(levels: LogLevel[]): void;
|
|
29
13
|
log(message: unknown, ...optionalParams: unknown[]): void;
|
|
30
14
|
error(message: unknown, ...optionalParams: unknown[]): void;
|
|
@@ -46,7 +30,7 @@ declare abstract class BasePinoLogger implements LoggerService {
|
|
|
46
30
|
private static looksLikeStack;
|
|
47
31
|
}
|
|
48
32
|
declare class AppLogger extends BasePinoLogger {
|
|
49
|
-
constructor(logger: Logger, requestContext: RequestContextService);
|
|
33
|
+
constructor(logger: Logger, observableService: ObservableService, requestContext: RequestContextService);
|
|
50
34
|
}
|
|
51
35
|
declare class PinoLoggerService extends BasePinoLogger {
|
|
52
36
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,30 +1,14 @@
|
|
|
1
1
|
import { LoggerService, LogLevel, NestMiddleware } from '@nestjs/common';
|
|
2
2
|
import { Logger } from 'pino';
|
|
3
|
+
import { RequestContextService, ObservableService } from '@lark-apaas/nestjs-common';
|
|
3
4
|
import { Request, Response, NextFunction } from 'express';
|
|
4
5
|
|
|
5
|
-
interface RequestContextState {
|
|
6
|
-
requestId: string;
|
|
7
|
-
path?: string;
|
|
8
|
-
method?: string;
|
|
9
|
-
userId?: string;
|
|
10
|
-
appId?: string;
|
|
11
|
-
tenantId?: string;
|
|
12
|
-
ip?: string;
|
|
13
|
-
[key: string]: unknown;
|
|
14
|
-
}
|
|
15
|
-
declare class RequestContextService {
|
|
16
|
-
private readonly storage;
|
|
17
|
-
run<T>(context: RequestContextState, callback: () => T): T;
|
|
18
|
-
setContext(partial: Partial<RequestContextState>): void;
|
|
19
|
-
getContext(): RequestContextState | undefined;
|
|
20
|
-
get<K extends keyof RequestContextState>(key: K): RequestContextState[K] | undefined;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
6
|
declare abstract class BasePinoLogger implements LoggerService {
|
|
24
7
|
protected readonly logger: Logger;
|
|
25
8
|
protected readonly contextStore: RequestContextService;
|
|
9
|
+
protected readonly observableService: ObservableService;
|
|
26
10
|
private readonly levelState;
|
|
27
|
-
constructor(logger: Logger, contextStore: RequestContextService);
|
|
11
|
+
constructor(logger: Logger, contextStore: RequestContextService, observableService: ObservableService);
|
|
28
12
|
setLogLevels(levels: LogLevel[]): void;
|
|
29
13
|
log(message: unknown, ...optionalParams: unknown[]): void;
|
|
30
14
|
error(message: unknown, ...optionalParams: unknown[]): void;
|
|
@@ -46,7 +30,7 @@ declare abstract class BasePinoLogger implements LoggerService {
|
|
|
46
30
|
private static looksLikeStack;
|
|
47
31
|
}
|
|
48
32
|
declare class AppLogger extends BasePinoLogger {
|
|
49
|
-
constructor(logger: Logger, requestContext: RequestContextService);
|
|
33
|
+
constructor(logger: Logger, observableService: ObservableService, requestContext: RequestContextService);
|
|
50
34
|
}
|
|
51
35
|
declare class PinoLoggerService extends BasePinoLogger {
|
|
52
36
|
}
|
package/dist/index.js
CHANGED
|
@@ -452,7 +452,7 @@ var require_config_constants = __commonJS({
|
|
|
452
452
|
value: true
|
|
453
453
|
});
|
|
454
454
|
exports.AS_PROVIDER_METHOD_KEY = exports.VALIDATED_ENV_PROPNAME = exports.PARTIAL_CONFIGURATION_PROPNAME = exports.PARTIAL_CONFIGURATION_KEY = exports.VALIDATED_ENV_LOADER = exports.CONFIGURATION_LOADER = exports.CONFIGURATION_TOKEN = exports.CONFIGURATION_SERVICE_TOKEN = void 0;
|
|
455
|
-
exports.CONFIGURATION_SERVICE_TOKEN = Symbol("CONFIG_SERVICE");
|
|
455
|
+
exports.CONFIGURATION_SERVICE_TOKEN = /* @__PURE__ */ Symbol("CONFIG_SERVICE");
|
|
456
456
|
exports.CONFIGURATION_TOKEN = "CONFIGURATION_TOKEN";
|
|
457
457
|
exports.CONFIGURATION_LOADER = "CONFIGURATION_LOADER";
|
|
458
458
|
exports.VALIDATED_ENV_LOADER = "VALIDATED_ENV_LOADER";
|
|
@@ -14370,17 +14370,14 @@ var require_operators = __commonJS({
|
|
|
14370
14370
|
});
|
|
14371
14371
|
|
|
14372
14372
|
// src/service/app-logger.service.ts
|
|
14373
|
-
import { Inject, Injectable
|
|
14374
|
-
import { inspect } from "util";
|
|
14373
|
+
import { Inject, Injectable, Logger } from "@nestjs/common";
|
|
14375
14374
|
|
|
14376
14375
|
// src/helper/constants.ts
|
|
14377
|
-
var PINO_ROOT_LOGGER = Symbol("PINO_ROOT_LOGGER");
|
|
14378
|
-
var TRACE_LOGGER = Symbol("TRACE_LOGGER");
|
|
14379
|
-
var METRICS_LOGGER = Symbol("METRICS_LOGGER");
|
|
14376
|
+
var PINO_ROOT_LOGGER = /* @__PURE__ */ Symbol("PINO_ROOT_LOGGER");
|
|
14377
|
+
var TRACE_LOGGER = /* @__PURE__ */ Symbol("TRACE_LOGGER");
|
|
14380
14378
|
|
|
14381
|
-
// src/service/
|
|
14382
|
-
import {
|
|
14383
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
14379
|
+
// src/service/app-logger.service.ts
|
|
14380
|
+
import { RequestContextService, OBSERVABLE_SERVICE, ObservableService } from "@lark-apaas/nestjs-common";
|
|
14384
14381
|
function _ts_decorate(decorators, target, key, desc) {
|
|
14385
14382
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
14386
14383
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -14388,43 +14385,6 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
14388
14385
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
14389
14386
|
}
|
|
14390
14387
|
__name(_ts_decorate, "_ts_decorate");
|
|
14391
|
-
var RequestContextService = class {
|
|
14392
|
-
static {
|
|
14393
|
-
__name(this, "RequestContextService");
|
|
14394
|
-
}
|
|
14395
|
-
storage = new AsyncLocalStorage();
|
|
14396
|
-
run(context, callback) {
|
|
14397
|
-
const store = {
|
|
14398
|
-
...context
|
|
14399
|
-
};
|
|
14400
|
-
return this.storage.run(store, callback);
|
|
14401
|
-
}
|
|
14402
|
-
setContext(partial) {
|
|
14403
|
-
const store = this.storage.getStore();
|
|
14404
|
-
if (!store) {
|
|
14405
|
-
return;
|
|
14406
|
-
}
|
|
14407
|
-
Object.assign(store, partial);
|
|
14408
|
-
}
|
|
14409
|
-
getContext() {
|
|
14410
|
-
return this.storage.getStore();
|
|
14411
|
-
}
|
|
14412
|
-
get(key) {
|
|
14413
|
-
return this.storage.getStore()?.[key];
|
|
14414
|
-
}
|
|
14415
|
-
};
|
|
14416
|
-
RequestContextService = _ts_decorate([
|
|
14417
|
-
Injectable()
|
|
14418
|
-
], RequestContextService);
|
|
14419
|
-
|
|
14420
|
-
// src/service/app-logger.service.ts
|
|
14421
|
-
function _ts_decorate2(decorators, target, key, desc) {
|
|
14422
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
14423
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
14424
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
14425
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
14426
|
-
}
|
|
14427
|
-
__name(_ts_decorate2, "_ts_decorate");
|
|
14428
14388
|
function _ts_metadata(k, v) {
|
|
14429
14389
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
14430
14390
|
}
|
|
@@ -14532,10 +14492,12 @@ var BasePinoLogger = class _BasePinoLogger {
|
|
|
14532
14492
|
}
|
|
14533
14493
|
logger;
|
|
14534
14494
|
contextStore;
|
|
14495
|
+
observableService;
|
|
14535
14496
|
levelState = new LogLevelState();
|
|
14536
|
-
constructor(logger, contextStore) {
|
|
14497
|
+
constructor(logger, contextStore, observableService) {
|
|
14537
14498
|
this.logger = logger;
|
|
14538
14499
|
this.contextStore = contextStore;
|
|
14500
|
+
this.observableService = observableService;
|
|
14539
14501
|
const pinoLevel = this.logger.level;
|
|
14540
14502
|
const nestLevels = LogLevelState.fromPinoLevel(pinoLevel);
|
|
14541
14503
|
this.levelState.set(nestLevels);
|
|
@@ -14599,6 +14561,26 @@ var BasePinoLogger = class _BasePinoLogger {
|
|
|
14599
14561
|
const { context, stack, extras } = this.extractOptionalParams(optionalParams, treatStack);
|
|
14600
14562
|
const requestState = this.contextStore.getContext();
|
|
14601
14563
|
const traceId = requestState?.requestId ?? null;
|
|
14564
|
+
const flatObject = /* @__PURE__ */ __name((extra) => {
|
|
14565
|
+
let res = {};
|
|
14566
|
+
try {
|
|
14567
|
+
extra.forEach((item) => {
|
|
14568
|
+
if (typeof item === "object" && item !== null) {
|
|
14569
|
+
res = {
|
|
14570
|
+
...res,
|
|
14571
|
+
...item
|
|
14572
|
+
};
|
|
14573
|
+
}
|
|
14574
|
+
});
|
|
14575
|
+
delete res.message;
|
|
14576
|
+
delete res.level;
|
|
14577
|
+
delete res.time;
|
|
14578
|
+
delete res.context;
|
|
14579
|
+
return res;
|
|
14580
|
+
} catch {
|
|
14581
|
+
}
|
|
14582
|
+
}, "flatObject");
|
|
14583
|
+
const processedExtra = flatObject(extras);
|
|
14602
14584
|
const payload = {
|
|
14603
14585
|
trace_id: traceId,
|
|
14604
14586
|
path: requestState?.path,
|
|
@@ -14606,12 +14588,13 @@ var BasePinoLogger = class _BasePinoLogger {
|
|
|
14606
14588
|
user_id: requestState?.userId ?? null,
|
|
14607
14589
|
app_id: requestState?.appId ?? null,
|
|
14608
14590
|
tenant_id: requestState?.tenantId ?? null,
|
|
14609
|
-
pid: process.pid
|
|
14591
|
+
pid: process.pid,
|
|
14592
|
+
...processedExtra
|
|
14610
14593
|
};
|
|
14611
14594
|
if (context) {
|
|
14612
14595
|
payload.context = context;
|
|
14613
14596
|
}
|
|
14614
|
-
const { messageText, stack: computedStack, data } = this.buildMessagePayload(message
|
|
14597
|
+
const { messageText, stack: computedStack, data } = this.buildMessagePayload(message);
|
|
14615
14598
|
if (stack) {
|
|
14616
14599
|
payload.stack = stack;
|
|
14617
14600
|
} else if (computedStack) {
|
|
@@ -14622,10 +14605,14 @@ var BasePinoLogger = class _BasePinoLogger {
|
|
|
14622
14605
|
}
|
|
14623
14606
|
const pinoLevel = mapLogLevelToPino(level);
|
|
14624
14607
|
const sanitizedPayload = sanitizeValue(payload);
|
|
14625
|
-
if (
|
|
14626
|
-
|
|
14608
|
+
if (process.env.NODE_ENV === "development") {
|
|
14609
|
+
if (messageText) {
|
|
14610
|
+
this.logger[pinoLevel](sanitizedPayload, messageText);
|
|
14611
|
+
} else {
|
|
14612
|
+
this.logger[pinoLevel](sanitizedPayload);
|
|
14613
|
+
}
|
|
14627
14614
|
} else {
|
|
14628
|
-
this.
|
|
14615
|
+
this.observableService.log(level, messageText ?? "", payload);
|
|
14629
14616
|
}
|
|
14630
14617
|
}
|
|
14631
14618
|
extractOptionalParams(optionalParams, treatStack) {
|
|
@@ -14654,7 +14641,7 @@ var BasePinoLogger = class _BasePinoLogger {
|
|
|
14654
14641
|
extras: params
|
|
14655
14642
|
};
|
|
14656
14643
|
}
|
|
14657
|
-
buildMessagePayload(message
|
|
14644
|
+
buildMessagePayload(message) {
|
|
14658
14645
|
if (message instanceof Error) {
|
|
14659
14646
|
return {
|
|
14660
14647
|
messageText: message.message,
|
|
@@ -14662,17 +14649,8 @@ var BasePinoLogger = class _BasePinoLogger {
|
|
|
14662
14649
|
};
|
|
14663
14650
|
}
|
|
14664
14651
|
if (typeof message === "string") {
|
|
14665
|
-
if (extras.length === 0) {
|
|
14666
|
-
return {
|
|
14667
|
-
messageText: message
|
|
14668
|
-
};
|
|
14669
|
-
}
|
|
14670
|
-
const allMessages = [
|
|
14671
|
-
message,
|
|
14672
|
-
...extras.map((e) => stringifyParam(e))
|
|
14673
|
-
].join(" ");
|
|
14674
14652
|
return {
|
|
14675
|
-
messageText:
|
|
14653
|
+
messageText: message
|
|
14676
14654
|
};
|
|
14677
14655
|
}
|
|
14678
14656
|
if (typeof message === "object" && message !== null) {
|
|
@@ -14695,17 +14673,19 @@ var AppLogger = class extends BasePinoLogger {
|
|
|
14695
14673
|
static {
|
|
14696
14674
|
__name(this, "AppLogger");
|
|
14697
14675
|
}
|
|
14698
|
-
constructor(logger, requestContext) {
|
|
14699
|
-
super(logger, requestContext);
|
|
14676
|
+
constructor(logger, observableService, requestContext) {
|
|
14677
|
+
super(logger, requestContext, observableService);
|
|
14700
14678
|
Logger.overrideLogger(this);
|
|
14701
14679
|
}
|
|
14702
14680
|
};
|
|
14703
|
-
AppLogger =
|
|
14704
|
-
|
|
14681
|
+
AppLogger = _ts_decorate([
|
|
14682
|
+
Injectable(),
|
|
14705
14683
|
_ts_param(0, Inject(PINO_ROOT_LOGGER)),
|
|
14684
|
+
_ts_param(1, Inject(OBSERVABLE_SERVICE)),
|
|
14706
14685
|
_ts_metadata("design:type", Function),
|
|
14707
14686
|
_ts_metadata("design:paramtypes", [
|
|
14708
14687
|
typeof PinoLogger === "undefined" ? Object : PinoLogger,
|
|
14688
|
+
typeof ObservableService === "undefined" ? Object : ObservableService,
|
|
14709
14689
|
typeof RequestContextService === "undefined" ? Object : RequestContextService
|
|
14710
14690
|
])
|
|
14711
14691
|
], AppLogger);
|
|
@@ -14732,18 +14712,6 @@ function mapLogLevelToPino(level) {
|
|
|
14732
14712
|
}
|
|
14733
14713
|
}
|
|
14734
14714
|
__name(mapLogLevelToPino, "mapLogLevelToPino");
|
|
14735
|
-
function stringifyParam(param) {
|
|
14736
|
-
if (typeof param === "string") {
|
|
14737
|
-
return param;
|
|
14738
|
-
}
|
|
14739
|
-
const inspectOptions = {
|
|
14740
|
-
depth: 4,
|
|
14741
|
-
colors: false,
|
|
14742
|
-
compact: true
|
|
14743
|
-
};
|
|
14744
|
-
return inspect(param, inspectOptions);
|
|
14745
|
-
}
|
|
14746
|
-
__name(stringifyParam, "stringifyParam");
|
|
14747
14715
|
function sanitizeValue(value) {
|
|
14748
14716
|
if (value === null || value === void 0) {
|
|
14749
14717
|
return value;
|
|
@@ -14769,6 +14737,7 @@ __name(sanitizeValue, "sanitizeValue");
|
|
|
14769
14737
|
var import_config3 = __toESM(require_config2(), 1);
|
|
14770
14738
|
import { Global, Module } from "@nestjs/common";
|
|
14771
14739
|
import { APP_INTERCEPTOR } from "@nestjs/core";
|
|
14740
|
+
import { OBSERVABLE_SERVICE as OBSERVABLE_SERVICE2, RequestContextService as RequestContextService4 } from "@lark-apaas/nestjs-common";
|
|
14772
14741
|
|
|
14773
14742
|
// src/config/logger.config.ts
|
|
14774
14743
|
var import_config = __toESM(require_config2(), 1);
|
|
@@ -14804,15 +14773,16 @@ var logger_config_default = (0, import_config.registerAs)("logger", () => {
|
|
|
14804
14773
|
// src/interceptor/logging.interceptor.ts
|
|
14805
14774
|
var import_config2 = __toESM(require_config2(), 1);
|
|
14806
14775
|
var import_operators = __toESM(require_operators(), 1);
|
|
14807
|
-
import { Inject as Inject2, Injectable as
|
|
14776
|
+
import { Inject as Inject2, Injectable as Injectable2 } from "@nestjs/common";
|
|
14808
14777
|
import { format } from "util";
|
|
14809
|
-
|
|
14778
|
+
import { RequestContextService as RequestContextService2 } from "@lark-apaas/nestjs-common";
|
|
14779
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
14810
14780
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
14811
14781
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
14812
14782
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
14813
14783
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
14814
14784
|
}
|
|
14815
|
-
__name(
|
|
14785
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
14816
14786
|
function _ts_metadata2(k, v) {
|
|
14817
14787
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
14818
14788
|
}
|
|
@@ -14961,20 +14931,21 @@ duration_ms=${durationMs}`, "HTTPTraceInterceptor");
|
|
|
14961
14931
|
return {
|
|
14962
14932
|
_error: "Failed to serialize data",
|
|
14963
14933
|
_type: typeof data,
|
|
14934
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14964
14935
|
_constructor: data?.constructor?.name
|
|
14965
14936
|
};
|
|
14966
14937
|
}
|
|
14967
14938
|
}
|
|
14968
14939
|
};
|
|
14969
|
-
LoggingInterceptor =
|
|
14970
|
-
|
|
14940
|
+
LoggingInterceptor = _ts_decorate2([
|
|
14941
|
+
Injectable2(),
|
|
14971
14942
|
_ts_param2(0, Inject2(TRACE_LOGGER)),
|
|
14972
14943
|
_ts_param2(2, Inject2(AppLogger)),
|
|
14973
14944
|
_ts_param2(3, Inject2(logger_config_default.KEY)),
|
|
14974
14945
|
_ts_metadata2("design:type", Function),
|
|
14975
14946
|
_ts_metadata2("design:paramtypes", [
|
|
14976
14947
|
typeof PinoLoggerService === "undefined" ? Object : PinoLoggerService,
|
|
14977
|
-
typeof
|
|
14948
|
+
typeof RequestContextService2 === "undefined" ? Object : RequestContextService2,
|
|
14978
14949
|
typeof AppLogger === "undefined" ? Object : AppLogger,
|
|
14979
14950
|
typeof import_config2.ConfigType === "undefined" ? Object : import_config2.ConfigType
|
|
14980
14951
|
])
|
|
@@ -15031,15 +15002,16 @@ function createFileDestination(pathname) {
|
|
|
15031
15002
|
__name(createFileDestination, "createFileDestination");
|
|
15032
15003
|
|
|
15033
15004
|
// src/middleware/logger-context.middleware.ts
|
|
15034
|
-
import { Injectable as
|
|
15005
|
+
import { Injectable as Injectable3 } from "@nestjs/common";
|
|
15035
15006
|
import { randomUUID } from "crypto";
|
|
15036
|
-
|
|
15007
|
+
import { RequestContextService as RequestContextService3 } from "@lark-apaas/nestjs-common";
|
|
15008
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
15037
15009
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
15038
15010
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
15039
15011
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
15040
15012
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
15041
15013
|
}
|
|
15042
|
-
__name(
|
|
15014
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
15043
15015
|
function _ts_metadata3(k, v) {
|
|
15044
15016
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
15045
15017
|
}
|
|
@@ -15054,51 +15026,44 @@ var LoggerContextMiddleware = class {
|
|
|
15054
15026
|
}
|
|
15055
15027
|
use(req, res, next) {
|
|
15056
15028
|
const requestId = req.headers["x-tt-log-id"] ?? randomUUID();
|
|
15057
|
-
const path = req.originalUrl ?? req.url;
|
|
15058
|
-
const userContext = req.userContext ?? {};
|
|
15059
15029
|
const mutableReq = req;
|
|
15060
15030
|
mutableReq.requestId = requestId;
|
|
15061
15031
|
mutableReq.id = requestId;
|
|
15062
15032
|
res.setHeader("x-log-trace-id", requestId);
|
|
15063
|
-
this.requestContext.
|
|
15064
|
-
requestId
|
|
15065
|
-
|
|
15066
|
-
|
|
15067
|
-
userId: userContext.userId,
|
|
15068
|
-
tenantId: userContext.tenantId,
|
|
15069
|
-
appId: userContext.appId
|
|
15070
|
-
}, () => next());
|
|
15033
|
+
this.requestContext.setContext({
|
|
15034
|
+
requestId
|
|
15035
|
+
});
|
|
15036
|
+
next();
|
|
15071
15037
|
}
|
|
15072
15038
|
};
|
|
15073
|
-
LoggerContextMiddleware =
|
|
15074
|
-
|
|
15039
|
+
LoggerContextMiddleware = _ts_decorate3([
|
|
15040
|
+
Injectable3(),
|
|
15075
15041
|
_ts_metadata3("design:type", Function),
|
|
15076
15042
|
_ts_metadata3("design:paramtypes", [
|
|
15077
|
-
typeof
|
|
15043
|
+
typeof RequestContextService3 === "undefined" ? Object : RequestContextService3
|
|
15078
15044
|
])
|
|
15079
15045
|
], LoggerContextMiddleware);
|
|
15080
15046
|
|
|
15081
15047
|
// src/module.ts
|
|
15082
|
-
function
|
|
15048
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
15083
15049
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
15084
15050
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
15085
15051
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
15086
15052
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
15087
15053
|
}
|
|
15088
|
-
__name(
|
|
15054
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
15089
15055
|
var LoggerModule = class {
|
|
15090
15056
|
static {
|
|
15091
15057
|
__name(this, "LoggerModule");
|
|
15092
15058
|
}
|
|
15093
15059
|
};
|
|
15094
|
-
LoggerModule =
|
|
15060
|
+
LoggerModule = _ts_decorate4([
|
|
15095
15061
|
Global(),
|
|
15096
15062
|
Module({
|
|
15097
15063
|
imports: [
|
|
15098
15064
|
import_config3.ConfigModule.forFeature(logger_config_default)
|
|
15099
15065
|
],
|
|
15100
15066
|
providers: [
|
|
15101
|
-
RequestContextService,
|
|
15102
15067
|
LoggerContextMiddleware,
|
|
15103
15068
|
{
|
|
15104
15069
|
provide: PINO_ROOT_LOGGER,
|
|
@@ -15114,13 +15079,14 @@ LoggerModule = _ts_decorate5([
|
|
|
15114
15079
|
},
|
|
15115
15080
|
{
|
|
15116
15081
|
provide: TRACE_LOGGER,
|
|
15117
|
-
useFactory: /* @__PURE__ */ __name((requestContext, config) => new PinoLoggerService(createPinoLogger({
|
|
15082
|
+
useFactory: /* @__PURE__ */ __name((requestContext, config, observableService) => new PinoLoggerService(createPinoLogger({
|
|
15118
15083
|
level: config.level,
|
|
15119
15084
|
filePath: `${config.logDir}/trace.log`
|
|
15120
|
-
}), requestContext), "useFactory"),
|
|
15085
|
+
}), requestContext, observableService), "useFactory"),
|
|
15121
15086
|
inject: [
|
|
15122
|
-
|
|
15123
|
-
logger_config_default.KEY
|
|
15087
|
+
RequestContextService4,
|
|
15088
|
+
logger_config_default.KEY,
|
|
15089
|
+
OBSERVABLE_SERVICE2
|
|
15124
15090
|
]
|
|
15125
15091
|
},
|
|
15126
15092
|
AppLogger,
|
|
@@ -15133,7 +15099,6 @@ LoggerModule = _ts_decorate5([
|
|
|
15133
15099
|
exports: [
|
|
15134
15100
|
AppLogger,
|
|
15135
15101
|
TRACE_LOGGER,
|
|
15136
|
-
RequestContextService,
|
|
15137
15102
|
LoggerContextMiddleware
|
|
15138
15103
|
]
|
|
15139
15104
|
})
|