@lark-apaas/nestjs-logger 1.0.2-alpha.9 → 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 +26 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -5
- package/dist/index.d.ts +4 -5
- package/dist/index.js +28 -34
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.cts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
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
|
+
import { RequestContextService, ObservableService } from '@lark-apaas/nestjs-common';
|
|
5
4
|
import { Request, Response, NextFunction } from 'express';
|
|
6
5
|
|
|
7
6
|
declare abstract class BasePinoLogger implements LoggerService {
|
|
8
7
|
protected readonly logger: Logger;
|
|
9
8
|
protected readonly contextStore: RequestContextService;
|
|
9
|
+
protected readonly observableService: ObservableService;
|
|
10
10
|
private readonly levelState;
|
|
11
|
-
|
|
12
|
-
constructor(logger: Logger, contextStore: RequestContextService);
|
|
11
|
+
constructor(logger: Logger, contextStore: RequestContextService, observableService: ObservableService);
|
|
13
12
|
setLogLevels(levels: LogLevel[]): void;
|
|
14
13
|
log(message: unknown, ...optionalParams: unknown[]): void;
|
|
15
14
|
error(message: unknown, ...optionalParams: unknown[]): void;
|
|
@@ -31,7 +30,7 @@ declare abstract class BasePinoLogger implements LoggerService {
|
|
|
31
30
|
private static looksLikeStack;
|
|
32
31
|
}
|
|
33
32
|
declare class AppLogger extends BasePinoLogger {
|
|
34
|
-
constructor(logger: Logger, requestContext: RequestContextService);
|
|
33
|
+
constructor(logger: Logger, observableService: ObservableService, requestContext: RequestContextService);
|
|
35
34
|
}
|
|
36
35
|
declare class PinoLoggerService extends BasePinoLogger {
|
|
37
36
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
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
|
+
import { RequestContextService, ObservableService } from '@lark-apaas/nestjs-common';
|
|
5
4
|
import { Request, Response, NextFunction } from 'express';
|
|
6
5
|
|
|
7
6
|
declare abstract class BasePinoLogger implements LoggerService {
|
|
8
7
|
protected readonly logger: Logger;
|
|
9
8
|
protected readonly contextStore: RequestContextService;
|
|
9
|
+
protected readonly observableService: ObservableService;
|
|
10
10
|
private readonly levelState;
|
|
11
|
-
|
|
12
|
-
constructor(logger: Logger, contextStore: RequestContextService);
|
|
11
|
+
constructor(logger: Logger, contextStore: RequestContextService, observableService: ObservableService);
|
|
13
12
|
setLogLevels(levels: LogLevel[]): void;
|
|
14
13
|
log(message: unknown, ...optionalParams: unknown[]): void;
|
|
15
14
|
error(message: unknown, ...optionalParams: unknown[]): void;
|
|
@@ -31,7 +30,7 @@ declare abstract class BasePinoLogger implements LoggerService {
|
|
|
31
30
|
private static looksLikeStack;
|
|
32
31
|
}
|
|
33
32
|
declare class AppLogger extends BasePinoLogger {
|
|
34
|
-
constructor(logger: Logger, requestContext: RequestContextService);
|
|
33
|
+
constructor(logger: Logger, observableService: ObservableService, requestContext: RequestContextService);
|
|
35
34
|
}
|
|
36
35
|
declare class PinoLoggerService extends BasePinoLogger {
|
|
37
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";
|
|
@@ -14371,15 +14371,13 @@ var require_operators = __commonJS({
|
|
|
14371
14371
|
|
|
14372
14372
|
// src/service/app-logger.service.ts
|
|
14373
14373
|
import { Inject, Injectable, Logger } from "@nestjs/common";
|
|
14374
|
-
import { ObservableService } from "@lark-apaas/nestjs-observable";
|
|
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
14379
|
// src/service/app-logger.service.ts
|
|
14382
|
-
import { RequestContextService } from "@lark-apaas/nestjs-common";
|
|
14380
|
+
import { RequestContextService, OBSERVABLE_SERVICE, ObservableService } from "@lark-apaas/nestjs-common";
|
|
14383
14381
|
function _ts_decorate(decorators, target, key, desc) {
|
|
14384
14382
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
14385
14383
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -14494,11 +14492,12 @@ var BasePinoLogger = class _BasePinoLogger {
|
|
|
14494
14492
|
}
|
|
14495
14493
|
logger;
|
|
14496
14494
|
contextStore;
|
|
14495
|
+
observableService;
|
|
14497
14496
|
levelState = new LogLevelState();
|
|
14498
|
-
|
|
14499
|
-
constructor(logger, contextStore) {
|
|
14497
|
+
constructor(logger, contextStore, observableService) {
|
|
14500
14498
|
this.logger = logger;
|
|
14501
14499
|
this.contextStore = contextStore;
|
|
14500
|
+
this.observableService = observableService;
|
|
14502
14501
|
const pinoLevel = this.logger.level;
|
|
14503
14502
|
const nestLevels = LogLevelState.fromPinoLevel(pinoLevel);
|
|
14504
14503
|
this.levelState.set(nestLevels);
|
|
@@ -14606,12 +14605,15 @@ var BasePinoLogger = class _BasePinoLogger {
|
|
|
14606
14605
|
}
|
|
14607
14606
|
const pinoLevel = mapLogLevelToPino(level);
|
|
14608
14607
|
const sanitizedPayload = sanitizeValue(payload);
|
|
14609
|
-
if (
|
|
14610
|
-
|
|
14608
|
+
if (process.env.NODE_ENV === "development") {
|
|
14609
|
+
if (messageText) {
|
|
14610
|
+
this.logger[pinoLevel](sanitizedPayload, messageText);
|
|
14611
|
+
} else {
|
|
14612
|
+
this.logger[pinoLevel](sanitizedPayload);
|
|
14613
|
+
}
|
|
14611
14614
|
} else {
|
|
14612
|
-
this.
|
|
14615
|
+
this.observableService.log(level, messageText ?? "", payload);
|
|
14613
14616
|
}
|
|
14614
|
-
this.observableService.log(level, messageText ?? "", payload);
|
|
14615
14617
|
}
|
|
14616
14618
|
extractOptionalParams(optionalParams, treatStack) {
|
|
14617
14619
|
const params = [
|
|
@@ -14671,17 +14673,19 @@ var AppLogger = class extends BasePinoLogger {
|
|
|
14671
14673
|
static {
|
|
14672
14674
|
__name(this, "AppLogger");
|
|
14673
14675
|
}
|
|
14674
|
-
constructor(logger, requestContext) {
|
|
14675
|
-
super(logger, requestContext);
|
|
14676
|
+
constructor(logger, observableService, requestContext) {
|
|
14677
|
+
super(logger, requestContext, observableService);
|
|
14676
14678
|
Logger.overrideLogger(this);
|
|
14677
14679
|
}
|
|
14678
14680
|
};
|
|
14679
14681
|
AppLogger = _ts_decorate([
|
|
14680
14682
|
Injectable(),
|
|
14681
14683
|
_ts_param(0, Inject(PINO_ROOT_LOGGER)),
|
|
14684
|
+
_ts_param(1, Inject(OBSERVABLE_SERVICE)),
|
|
14682
14685
|
_ts_metadata("design:type", Function),
|
|
14683
14686
|
_ts_metadata("design:paramtypes", [
|
|
14684
14687
|
typeof PinoLogger === "undefined" ? Object : PinoLogger,
|
|
14688
|
+
typeof ObservableService === "undefined" ? Object : ObservableService,
|
|
14685
14689
|
typeof RequestContextService === "undefined" ? Object : RequestContextService
|
|
14686
14690
|
])
|
|
14687
14691
|
], AppLogger);
|
|
@@ -14733,7 +14737,7 @@ __name(sanitizeValue, "sanitizeValue");
|
|
|
14733
14737
|
var import_config3 = __toESM(require_config2(), 1);
|
|
14734
14738
|
import { Global, Module } from "@nestjs/common";
|
|
14735
14739
|
import { APP_INTERCEPTOR } from "@nestjs/core";
|
|
14736
|
-
import {
|
|
14740
|
+
import { OBSERVABLE_SERVICE as OBSERVABLE_SERVICE2, RequestContextService as RequestContextService4 } from "@lark-apaas/nestjs-common";
|
|
14737
14741
|
|
|
14738
14742
|
// src/config/logger.config.ts
|
|
14739
14743
|
var import_config = __toESM(require_config2(), 1);
|
|
@@ -15022,20 +15026,14 @@ var LoggerContextMiddleware = class {
|
|
|
15022
15026
|
}
|
|
15023
15027
|
use(req, res, next) {
|
|
15024
15028
|
const requestId = req.headers["x-tt-log-id"] ?? randomUUID();
|
|
15025
|
-
const path = req.originalUrl ?? req.url;
|
|
15026
|
-
const userContext = req.userContext ?? {};
|
|
15027
15029
|
const mutableReq = req;
|
|
15028
15030
|
mutableReq.requestId = requestId;
|
|
15029
15031
|
mutableReq.id = requestId;
|
|
15030
15032
|
res.setHeader("x-log-trace-id", requestId);
|
|
15031
|
-
this.requestContext.
|
|
15032
|
-
requestId
|
|
15033
|
-
|
|
15034
|
-
|
|
15035
|
-
userId: userContext.userId,
|
|
15036
|
-
tenantId: userContext.tenantId,
|
|
15037
|
-
appId: userContext.appId
|
|
15038
|
-
}, () => next());
|
|
15033
|
+
this.requestContext.setContext({
|
|
15034
|
+
requestId
|
|
15035
|
+
});
|
|
15036
|
+
next();
|
|
15039
15037
|
}
|
|
15040
15038
|
};
|
|
15041
15039
|
LoggerContextMiddleware = _ts_decorate3([
|
|
@@ -15063,8 +15061,7 @@ LoggerModule = _ts_decorate4([
|
|
|
15063
15061
|
Global(),
|
|
15064
15062
|
Module({
|
|
15065
15063
|
imports: [
|
|
15066
|
-
import_config3.ConfigModule.forFeature(logger_config_default)
|
|
15067
|
-
CommonModule
|
|
15064
|
+
import_config3.ConfigModule.forFeature(logger_config_default)
|
|
15068
15065
|
],
|
|
15069
15066
|
providers: [
|
|
15070
15067
|
LoggerContextMiddleware,
|
|
@@ -15082,13 +15079,14 @@ LoggerModule = _ts_decorate4([
|
|
|
15082
15079
|
},
|
|
15083
15080
|
{
|
|
15084
15081
|
provide: TRACE_LOGGER,
|
|
15085
|
-
useFactory: /* @__PURE__ */ __name((requestContext, config) => new PinoLoggerService(createPinoLogger({
|
|
15082
|
+
useFactory: /* @__PURE__ */ __name((requestContext, config, observableService) => new PinoLoggerService(createPinoLogger({
|
|
15086
15083
|
level: config.level,
|
|
15087
15084
|
filePath: `${config.logDir}/trace.log`
|
|
15088
|
-
}), requestContext), "useFactory"),
|
|
15085
|
+
}), requestContext, observableService), "useFactory"),
|
|
15089
15086
|
inject: [
|
|
15090
15087
|
RequestContextService4,
|
|
15091
|
-
logger_config_default.KEY
|
|
15088
|
+
logger_config_default.KEY,
|
|
15089
|
+
OBSERVABLE_SERVICE2
|
|
15092
15090
|
]
|
|
15093
15091
|
},
|
|
15094
15092
|
AppLogger,
|
|
@@ -15105,15 +15103,11 @@ LoggerModule = _ts_decorate4([
|
|
|
15105
15103
|
]
|
|
15106
15104
|
})
|
|
15107
15105
|
], LoggerModule);
|
|
15108
|
-
|
|
15109
|
-
// src/index.ts
|
|
15110
|
-
import { RequestContextService as RequestContextService5 } from "@lark-apaas/nestjs-common";
|
|
15111
15106
|
export {
|
|
15112
15107
|
AppLogger,
|
|
15113
15108
|
LoggerContextMiddleware,
|
|
15114
15109
|
LoggerModule,
|
|
15115
15110
|
PinoLoggerService,
|
|
15116
|
-
RequestContextService5 as RequestContextService,
|
|
15117
15111
|
TRACE_LOGGER
|
|
15118
15112
|
};
|
|
15119
15113
|
//# sourceMappingURL=index.js.map
|