@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 ADDED
@@ -0,0 +1,13 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Lark Technologies Pte. Ltd. and/or its affiliates
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted,provided that the above copyright notice and this permission notice appear in all copies.
6
+
7
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
8
+ IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
9
+ INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
10
+ EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
11
+ CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
12
+ DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
13
+ ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/dist/index.cjs CHANGED
@@ -452,7 +452,7 @@ var require_config_constants = __commonJS({
452
452
  value: true
453
453
  });
454
454
  exports2.AS_PROVIDER_METHOD_KEY = exports2.VALIDATED_ENV_PROPNAME = exports2.PARTIAL_CONFIGURATION_PROPNAME = exports2.PARTIAL_CONFIGURATION_KEY = exports2.VALIDATED_ENV_LOADER = exports2.CONFIGURATION_LOADER = exports2.CONFIGURATION_TOKEN = exports2.CONFIGURATION_SERVICE_TOKEN = void 0;
455
- exports2.CONFIGURATION_SERVICE_TOKEN = Symbol("CONFIG_SERVICE");
455
+ exports2.CONFIGURATION_SERVICE_TOKEN = /* @__PURE__ */ Symbol("CONFIG_SERVICE");
456
456
  exports2.CONFIGURATION_TOKEN = "CONFIGURATION_TOKEN";
457
457
  exports2.CONFIGURATION_LOADER = "CONFIGURATION_LOADER";
458
458
  exports2.VALIDATED_ENV_LOADER = "VALIDATED_ENV_LOADER";
@@ -14376,19 +14376,16 @@ __export(index_exports, {
14376
14376
  LoggerContextMiddleware: () => LoggerContextMiddleware,
14377
14377
  LoggerModule: () => LoggerModule,
14378
14378
  PinoLoggerService: () => PinoLoggerService,
14379
- RequestContextService: () => import_nestjs_common5.RequestContextService,
14380
14379
  TRACE_LOGGER: () => TRACE_LOGGER
14381
14380
  });
14382
14381
  module.exports = __toCommonJS(index_exports);
14383
14382
 
14384
14383
  // src/service/app-logger.service.ts
14385
14384
  var import_common = require("@nestjs/common");
14386
- var import_nestjs_observable = require("@lark-apaas/nestjs-observable");
14387
14385
 
14388
14386
  // src/helper/constants.ts
14389
- var PINO_ROOT_LOGGER = Symbol("PINO_ROOT_LOGGER");
14390
- var TRACE_LOGGER = Symbol("TRACE_LOGGER");
14391
- var METRICS_LOGGER = Symbol("METRICS_LOGGER");
14387
+ var PINO_ROOT_LOGGER = /* @__PURE__ */ Symbol("PINO_ROOT_LOGGER");
14388
+ var TRACE_LOGGER = /* @__PURE__ */ Symbol("TRACE_LOGGER");
14392
14389
 
14393
14390
  // src/service/app-logger.service.ts
14394
14391
  var import_nestjs_common = require("@lark-apaas/nestjs-common");
@@ -14506,11 +14503,12 @@ var BasePinoLogger = class _BasePinoLogger {
14506
14503
  }
14507
14504
  logger;
14508
14505
  contextStore;
14506
+ observableService;
14509
14507
  levelState = new LogLevelState();
14510
- observableService = new import_nestjs_observable.ObservableService();
14511
- constructor(logger, contextStore) {
14508
+ constructor(logger, contextStore, observableService) {
14512
14509
  this.logger = logger;
14513
14510
  this.contextStore = contextStore;
14511
+ this.observableService = observableService;
14514
14512
  const pinoLevel = this.logger.level;
14515
14513
  const nestLevels = LogLevelState.fromPinoLevel(pinoLevel);
14516
14514
  this.levelState.set(nestLevels);
@@ -14618,12 +14616,15 @@ var BasePinoLogger = class _BasePinoLogger {
14618
14616
  }
14619
14617
  const pinoLevel = mapLogLevelToPino(level);
14620
14618
  const sanitizedPayload = sanitizeValue(payload);
14621
- if (messageText) {
14622
- this.logger[pinoLevel](sanitizedPayload, messageText);
14619
+ if (process.env.NODE_ENV === "development") {
14620
+ if (messageText) {
14621
+ this.logger[pinoLevel](sanitizedPayload, messageText);
14622
+ } else {
14623
+ this.logger[pinoLevel](sanitizedPayload);
14624
+ }
14623
14625
  } else {
14624
- this.logger[pinoLevel](sanitizedPayload);
14626
+ this.observableService.log(level, messageText ?? "", payload);
14625
14627
  }
14626
- this.observableService.log(level, messageText ?? "", payload);
14627
14628
  }
14628
14629
  extractOptionalParams(optionalParams, treatStack) {
14629
14630
  const params = [
@@ -14683,17 +14684,19 @@ var AppLogger = class extends BasePinoLogger {
14683
14684
  static {
14684
14685
  __name(this, "AppLogger");
14685
14686
  }
14686
- constructor(logger, requestContext) {
14687
- super(logger, requestContext);
14687
+ constructor(logger, observableService, requestContext) {
14688
+ super(logger, requestContext, observableService);
14688
14689
  import_common.Logger.overrideLogger(this);
14689
14690
  }
14690
14691
  };
14691
14692
  AppLogger = _ts_decorate([
14692
14693
  (0, import_common.Injectable)(),
14693
14694
  _ts_param(0, (0, import_common.Inject)(PINO_ROOT_LOGGER)),
14695
+ _ts_param(1, (0, import_common.Inject)(import_nestjs_common.OBSERVABLE_SERVICE)),
14694
14696
  _ts_metadata("design:type", Function),
14695
14697
  _ts_metadata("design:paramtypes", [
14696
14698
  typeof PinoLogger === "undefined" ? Object : PinoLogger,
14699
+ typeof import_nestjs_common.ObservableService === "undefined" ? Object : import_nestjs_common.ObservableService,
14697
14700
  typeof import_nestjs_common.RequestContextService === "undefined" ? Object : import_nestjs_common.RequestContextService
14698
14701
  ])
14699
14702
  ], AppLogger);
@@ -15034,20 +15037,14 @@ var LoggerContextMiddleware = class {
15034
15037
  }
15035
15038
  use(req, res, next) {
15036
15039
  const requestId = req.headers["x-tt-log-id"] ?? (0, import_crypto.randomUUID)();
15037
- const path = req.originalUrl ?? req.url;
15038
- const userContext = req.userContext ?? {};
15039
15040
  const mutableReq = req;
15040
15041
  mutableReq.requestId = requestId;
15041
15042
  mutableReq.id = requestId;
15042
15043
  res.setHeader("x-log-trace-id", requestId);
15043
- this.requestContext.run({
15044
- requestId,
15045
- path,
15046
- method: req.method,
15047
- userId: userContext.userId,
15048
- tenantId: userContext.tenantId,
15049
- appId: userContext.appId
15050
- }, () => next());
15044
+ this.requestContext.setContext({
15045
+ requestId
15046
+ });
15047
+ next();
15051
15048
  }
15052
15049
  };
15053
15050
  LoggerContextMiddleware = _ts_decorate3([
@@ -15075,8 +15072,7 @@ LoggerModule = _ts_decorate4([
15075
15072
  (0, import_common4.Global)(),
15076
15073
  (0, import_common4.Module)({
15077
15074
  imports: [
15078
- import_config3.ConfigModule.forFeature(logger_config_default),
15079
- import_nestjs_common4.CommonModule
15075
+ import_config3.ConfigModule.forFeature(logger_config_default)
15080
15076
  ],
15081
15077
  providers: [
15082
15078
  LoggerContextMiddleware,
@@ -15094,13 +15090,14 @@ LoggerModule = _ts_decorate4([
15094
15090
  },
15095
15091
  {
15096
15092
  provide: TRACE_LOGGER,
15097
- useFactory: /* @__PURE__ */ __name((requestContext, config) => new PinoLoggerService(createPinoLogger({
15093
+ useFactory: /* @__PURE__ */ __name((requestContext, config, observableService) => new PinoLoggerService(createPinoLogger({
15098
15094
  level: config.level,
15099
15095
  filePath: `${config.logDir}/trace.log`
15100
- }), requestContext), "useFactory"),
15096
+ }), requestContext, observableService), "useFactory"),
15101
15097
  inject: [
15102
15098
  import_nestjs_common4.RequestContextService,
15103
- logger_config_default.KEY
15099
+ logger_config_default.KEY,
15100
+ import_nestjs_common4.OBSERVABLE_SERVICE
15104
15101
  ]
15105
15102
  },
15106
15103
  AppLogger,
@@ -15117,16 +15114,12 @@ LoggerModule = _ts_decorate4([
15117
15114
  ]
15118
15115
  })
15119
15116
  ], LoggerModule);
15120
-
15121
- // src/index.ts
15122
- var import_nestjs_common5 = require("@lark-apaas/nestjs-common");
15123
15117
  // Annotate the CommonJS export names for ESM import in node:
15124
15118
  0 && (module.exports = {
15125
15119
  AppLogger,
15126
15120
  LoggerContextMiddleware,
15127
15121
  LoggerModule,
15128
15122
  PinoLoggerService,
15129
- RequestContextService,
15130
15123
  TRACE_LOGGER
15131
15124
  });
15132
15125
  //# sourceMappingURL=index.cjs.map