@lark-apaas/nestjs-logger 1.0.2-alpha.1 → 1.0.2-alpha.3
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/dist/index.cjs +48 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -18
- package/dist/index.d.ts +2 -18
- package/dist/index.js +39 -67
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,25 +1,9 @@
|
|
|
1
1
|
import { LoggerService, LogLevel, NestMiddleware } from '@nestjs/common';
|
|
2
2
|
import { Logger } from 'pino';
|
|
3
|
+
import { RequestContextService } from '@lark-apaas/nestjs-common';
|
|
4
|
+
export { RequestContextService } from '@lark-apaas/nestjs-common';
|
|
3
5
|
import { Request, Response, NextFunction } from 'express';
|
|
4
6
|
|
|
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
7
|
declare abstract class BasePinoLogger implements LoggerService {
|
|
24
8
|
protected readonly logger: Logger;
|
|
25
9
|
protected readonly contextStore: RequestContextService;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,25 +1,9 @@
|
|
|
1
1
|
import { LoggerService, LogLevel, NestMiddleware } from '@nestjs/common';
|
|
2
2
|
import { Logger } from 'pino';
|
|
3
|
+
import { RequestContextService } from '@lark-apaas/nestjs-common';
|
|
4
|
+
export { RequestContextService } from '@lark-apaas/nestjs-common';
|
|
3
5
|
import { Request, Response, NextFunction } from 'express';
|
|
4
6
|
|
|
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
7
|
declare abstract class BasePinoLogger implements LoggerService {
|
|
24
8
|
protected readonly logger: Logger;
|
|
25
9
|
protected readonly contextStore: RequestContextService;
|
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 =
|
|
455
|
+
exports.CONFIGURATION_SERVICE_TOKEN = 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,17 @@ var require_operators = __commonJS({
|
|
|
14370
14370
|
});
|
|
14371
14371
|
|
|
14372
14372
|
// src/service/app-logger.service.ts
|
|
14373
|
-
import { Inject, Injectable
|
|
14373
|
+
import { Inject, Injectable, Logger } from "@nestjs/common";
|
|
14374
14374
|
import { inspect } from "util";
|
|
14375
|
-
import {
|
|
14375
|
+
import { appSdk } from "@lark-apaas/observable";
|
|
14376
14376
|
|
|
14377
14377
|
// src/helper/constants.ts
|
|
14378
|
-
var PINO_ROOT_LOGGER =
|
|
14379
|
-
var TRACE_LOGGER =
|
|
14378
|
+
var PINO_ROOT_LOGGER = Symbol("PINO_ROOT_LOGGER");
|
|
14379
|
+
var TRACE_LOGGER = Symbol("TRACE_LOGGER");
|
|
14380
|
+
var METRICS_LOGGER = Symbol("METRICS_LOGGER");
|
|
14380
14381
|
|
|
14381
|
-
// src/service/
|
|
14382
|
-
import {
|
|
14383
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
14382
|
+
// src/service/app-logger.service.ts
|
|
14383
|
+
import { RequestContextService } from "@lark-apaas/nestjs-common";
|
|
14384
14384
|
function _ts_decorate(decorators, target, key, desc) {
|
|
14385
14385
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
14386
14386
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -14388,43 +14388,6 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
14388
14388
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
14389
14389
|
}
|
|
14390
14390
|
__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
14391
|
function _ts_metadata(k, v) {
|
|
14429
14392
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
14430
14393
|
}
|
|
@@ -14533,7 +14496,7 @@ var BasePinoLogger = class _BasePinoLogger {
|
|
|
14533
14496
|
logger;
|
|
14534
14497
|
contextStore;
|
|
14535
14498
|
levelState = new LogLevelState();
|
|
14536
|
-
otelLogger =
|
|
14499
|
+
otelLogger = appSdk;
|
|
14537
14500
|
constructor(logger, contextStore) {
|
|
14538
14501
|
this.logger = logger;
|
|
14539
14502
|
this.contextStore = contextStore;
|
|
@@ -14629,7 +14592,8 @@ var BasePinoLogger = class _BasePinoLogger {
|
|
|
14629
14592
|
} else {
|
|
14630
14593
|
this.logger[pinoLevel](sanitizedPayload);
|
|
14631
14594
|
}
|
|
14632
|
-
|
|
14595
|
+
console.log("csh sanitizedPayload111111111", optionalParams?.[0] ?? {});
|
|
14596
|
+
this.otelLogger.log(level, messageText ?? "", optionalParams?.[0] ?? {});
|
|
14633
14597
|
}
|
|
14634
14598
|
extractOptionalParams(optionalParams, treatStack) {
|
|
14635
14599
|
const params = [
|
|
@@ -14703,8 +14667,8 @@ var AppLogger = class extends BasePinoLogger {
|
|
|
14703
14667
|
Logger.overrideLogger(this);
|
|
14704
14668
|
}
|
|
14705
14669
|
};
|
|
14706
|
-
AppLogger =
|
|
14707
|
-
|
|
14670
|
+
AppLogger = _ts_decorate([
|
|
14671
|
+
Injectable(),
|
|
14708
14672
|
_ts_param(0, Inject(PINO_ROOT_LOGGER)),
|
|
14709
14673
|
_ts_metadata("design:type", Function),
|
|
14710
14674
|
_ts_metadata("design:paramtypes", [
|
|
@@ -14772,6 +14736,7 @@ __name(sanitizeValue, "sanitizeValue");
|
|
|
14772
14736
|
var import_config3 = __toESM(require_config2(), 1);
|
|
14773
14737
|
import { Global, Module } from "@nestjs/common";
|
|
14774
14738
|
import { APP_INTERCEPTOR } from "@nestjs/core";
|
|
14739
|
+
import { RequestContextService as RequestContextService4 } from "@lark-apaas/nestjs-common";
|
|
14775
14740
|
|
|
14776
14741
|
// src/config/logger.config.ts
|
|
14777
14742
|
var import_config = __toESM(require_config2(), 1);
|
|
@@ -14807,15 +14772,16 @@ var logger_config_default = (0, import_config.registerAs)("logger", () => {
|
|
|
14807
14772
|
// src/interceptor/logging.interceptor.ts
|
|
14808
14773
|
var import_config2 = __toESM(require_config2(), 1);
|
|
14809
14774
|
var import_operators = __toESM(require_operators(), 1);
|
|
14810
|
-
import { Inject as Inject2, Injectable as
|
|
14775
|
+
import { Inject as Inject2, Injectable as Injectable2 } from "@nestjs/common";
|
|
14811
14776
|
import { format } from "util";
|
|
14812
|
-
|
|
14777
|
+
import { RequestContextService as RequestContextService2 } from "@lark-apaas/nestjs-common";
|
|
14778
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
14813
14779
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
14814
14780
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
14815
14781
|
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;
|
|
14816
14782
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
14817
14783
|
}
|
|
14818
|
-
__name(
|
|
14784
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
14819
14785
|
function _ts_metadata2(k, v) {
|
|
14820
14786
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
14821
14787
|
}
|
|
@@ -14964,20 +14930,21 @@ duration_ms=${durationMs}`, "HTTPTraceInterceptor");
|
|
|
14964
14930
|
return {
|
|
14965
14931
|
_error: "Failed to serialize data",
|
|
14966
14932
|
_type: typeof data,
|
|
14933
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14967
14934
|
_constructor: data?.constructor?.name
|
|
14968
14935
|
};
|
|
14969
14936
|
}
|
|
14970
14937
|
}
|
|
14971
14938
|
};
|
|
14972
|
-
LoggingInterceptor =
|
|
14973
|
-
|
|
14939
|
+
LoggingInterceptor = _ts_decorate2([
|
|
14940
|
+
Injectable2(),
|
|
14974
14941
|
_ts_param2(0, Inject2(TRACE_LOGGER)),
|
|
14975
14942
|
_ts_param2(2, Inject2(AppLogger)),
|
|
14976
14943
|
_ts_param2(3, Inject2(logger_config_default.KEY)),
|
|
14977
14944
|
_ts_metadata2("design:type", Function),
|
|
14978
14945
|
_ts_metadata2("design:paramtypes", [
|
|
14979
14946
|
typeof PinoLoggerService === "undefined" ? Object : PinoLoggerService,
|
|
14980
|
-
typeof
|
|
14947
|
+
typeof RequestContextService2 === "undefined" ? Object : RequestContextService2,
|
|
14981
14948
|
typeof AppLogger === "undefined" ? Object : AppLogger,
|
|
14982
14949
|
typeof import_config2.ConfigType === "undefined" ? Object : import_config2.ConfigType
|
|
14983
14950
|
])
|
|
@@ -15034,15 +15001,16 @@ function createFileDestination(pathname) {
|
|
|
15034
15001
|
__name(createFileDestination, "createFileDestination");
|
|
15035
15002
|
|
|
15036
15003
|
// src/middleware/logger-context.middleware.ts
|
|
15037
|
-
import { Injectable as
|
|
15004
|
+
import { Injectable as Injectable3 } from "@nestjs/common";
|
|
15038
15005
|
import { randomUUID } from "crypto";
|
|
15039
|
-
|
|
15006
|
+
import { RequestContextService as RequestContextService3 } from "@lark-apaas/nestjs-common";
|
|
15007
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
15040
15008
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
15041
15009
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
15042
15010
|
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;
|
|
15043
15011
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
15044
15012
|
}
|
|
15045
|
-
__name(
|
|
15013
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
15046
15014
|
function _ts_metadata3(k, v) {
|
|
15047
15015
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
15048
15016
|
}
|
|
@@ -15073,35 +15041,35 @@ var LoggerContextMiddleware = class {
|
|
|
15073
15041
|
}, () => next());
|
|
15074
15042
|
}
|
|
15075
15043
|
};
|
|
15076
|
-
LoggerContextMiddleware =
|
|
15077
|
-
|
|
15044
|
+
LoggerContextMiddleware = _ts_decorate3([
|
|
15045
|
+
Injectable3(),
|
|
15078
15046
|
_ts_metadata3("design:type", Function),
|
|
15079
15047
|
_ts_metadata3("design:paramtypes", [
|
|
15080
|
-
typeof
|
|
15048
|
+
typeof RequestContextService3 === "undefined" ? Object : RequestContextService3
|
|
15081
15049
|
])
|
|
15082
15050
|
], LoggerContextMiddleware);
|
|
15083
15051
|
|
|
15084
15052
|
// src/module.ts
|
|
15085
|
-
function
|
|
15053
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
15086
15054
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
15087
15055
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
15088
15056
|
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;
|
|
15089
15057
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
15090
15058
|
}
|
|
15091
|
-
__name(
|
|
15059
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
15092
15060
|
var LoggerModule = class {
|
|
15093
15061
|
static {
|
|
15094
15062
|
__name(this, "LoggerModule");
|
|
15095
15063
|
}
|
|
15096
15064
|
};
|
|
15097
|
-
LoggerModule =
|
|
15065
|
+
LoggerModule = _ts_decorate4([
|
|
15098
15066
|
Global(),
|
|
15099
15067
|
Module({
|
|
15100
15068
|
imports: [
|
|
15101
15069
|
import_config3.ConfigModule.forFeature(logger_config_default)
|
|
15102
15070
|
],
|
|
15103
15071
|
providers: [
|
|
15104
|
-
|
|
15072
|
+
RequestContextService4,
|
|
15105
15073
|
LoggerContextMiddleware,
|
|
15106
15074
|
{
|
|
15107
15075
|
provide: PINO_ROOT_LOGGER,
|
|
@@ -15122,7 +15090,7 @@ LoggerModule = _ts_decorate5([
|
|
|
15122
15090
|
filePath: `${config.logDir}/trace.log`
|
|
15123
15091
|
}), requestContext), "useFactory"),
|
|
15124
15092
|
inject: [
|
|
15125
|
-
|
|
15093
|
+
RequestContextService4,
|
|
15126
15094
|
logger_config_default.KEY
|
|
15127
15095
|
]
|
|
15128
15096
|
},
|
|
@@ -15136,16 +15104,20 @@ LoggerModule = _ts_decorate5([
|
|
|
15136
15104
|
exports: [
|
|
15137
15105
|
AppLogger,
|
|
15138
15106
|
TRACE_LOGGER,
|
|
15139
|
-
|
|
15107
|
+
RequestContextService4,
|
|
15140
15108
|
LoggerContextMiddleware
|
|
15141
15109
|
]
|
|
15142
15110
|
})
|
|
15143
15111
|
], LoggerModule);
|
|
15112
|
+
|
|
15113
|
+
// src/index.ts
|
|
15114
|
+
import { RequestContextService as RequestContextService5 } from "@lark-apaas/nestjs-common";
|
|
15144
15115
|
export {
|
|
15145
15116
|
AppLogger,
|
|
15146
15117
|
LoggerContextMiddleware,
|
|
15147
15118
|
LoggerModule,
|
|
15148
15119
|
PinoLoggerService,
|
|
15120
|
+
RequestContextService5 as RequestContextService,
|
|
15149
15121
|
TRACE_LOGGER
|
|
15150
15122
|
};
|
|
15151
15123
|
//# sourceMappingURL=index.js.map
|