@lark-apaas/nestjs-logger 0.1.0-alpha.1 → 0.1.0-alpha.2

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.js CHANGED
@@ -14520,13 +14520,11 @@ var BasePinoLogger = class _BasePinoLogger {
14520
14520
  const traceId = requestState?.requestId ?? null;
14521
14521
  const payload = {
14522
14522
  trace_id: traceId,
14523
- requestId: traceId,
14524
14523
  path: requestState?.path,
14525
14524
  method: requestState?.method,
14526
14525
  user_id: requestState?.userId ?? null,
14527
14526
  app_id: requestState?.appId ?? null,
14528
14527
  tenant_id: requestState?.tenantId ?? null,
14529
- ip: requestState?.ip ?? null,
14530
14528
  pid: process.pid
14531
14529
  };
14532
14530
  if (context) {
@@ -14693,44 +14691,11 @@ function normalizeLevel(level) {
14693
14691
  }
14694
14692
  }
14695
14693
  __name(normalizeLevel, "normalizeLevel");
14696
- function parseDestinations(raw) {
14697
- if (!raw) {
14698
- return [
14699
- {
14700
- type: "stdout"
14701
- }
14702
- ];
14703
- }
14704
- return raw.split(",").map((token) => token.trim()).filter(Boolean).map((token) => {
14705
- const [typeAndPath, level] = token.split("@");
14706
- const [type, path] = typeAndPath.split(":");
14707
- const normalizedType = (type ?? "stdout").toLowerCase();
14708
- if (normalizedType === "file") {
14709
- return {
14710
- type: "file",
14711
- path: path || "logs/app.log",
14712
- level
14713
- };
14714
- }
14715
- if (normalizedType === "stderr") {
14716
- return {
14717
- type: "stderr",
14718
- level
14719
- };
14720
- }
14721
- return {
14722
- type: "stdout",
14723
- level
14724
- };
14725
- });
14726
- }
14727
- __name(parseDestinations, "parseDestinations");
14728
14694
  var logger_config_default = (0, import_config.registerAs)("logger", () => {
14729
14695
  const level = normalizeLevel(process.env.LOGGER_LEVEL || (process.env.NODE_ENV === "production" ? "info" : "debug"));
14730
- const destinations = parseDestinations(process.env.LOGGER_DESTINATIONS);
14731
14696
  return {
14732
14697
  level,
14733
- destinations
14698
+ logDir: process.env.LOG_DIR || "logs"
14734
14699
  };
14735
14700
  });
14736
14701
 
@@ -14844,12 +14809,12 @@ function createPinoLogger(config) {
14844
14809
  }
14845
14810
  }
14846
14811
  };
14847
- const destinations = config.destinations.length > 0 ? config.destinations : [
14812
+ const streams = [
14848
14813
  {
14849
- type: "stdout"
14814
+ level: config.level,
14815
+ stream: createFileDestination(config.filePath)
14850
14816
  }
14851
14817
  ];
14852
- const streams = buildStreams(destinations, baseLevel);
14853
14818
  if (streams.length === 0) {
14854
14819
  return pino(options);
14855
14820
  }
@@ -14859,30 +14824,6 @@ function createPinoLogger(config) {
14859
14824
  return pino(options, pino.multistream(streams));
14860
14825
  }
14861
14826
  __name(createPinoLogger, "createPinoLogger");
14862
- function buildStreams(destinations, fallbackLevel) {
14863
- return destinations.map((destination) => {
14864
- const level = normalizeLevel(destination.level ?? fallbackLevel);
14865
- switch (destination.type) {
14866
- case "stderr":
14867
- return {
14868
- level,
14869
- stream: process.stderr
14870
- };
14871
- case "file":
14872
- return {
14873
- level,
14874
- stream: createFileDestination(destination.path)
14875
- };
14876
- case "stdout":
14877
- default:
14878
- return {
14879
- level,
14880
- stream: process.stdout
14881
- };
14882
- }
14883
- });
14884
- }
14885
- __name(buildStreams, "buildStreams");
14886
14827
  function createFileDestination(pathname) {
14887
14828
  const target = pathname && pathname.length > 0 ? pathname : "logs/app.log";
14888
14829
  const resolved = isAbsolute(target) ? target : join(process.cwd(), target);
@@ -14970,25 +14911,25 @@ LoggerModule = _ts_decorate5([
14970
14911
  LoggerContextMiddleware,
14971
14912
  {
14972
14913
  provide: PINO_ROOT_LOGGER,
14973
- useFactory: /* @__PURE__ */ __name((config) => createPinoLogger(config), "useFactory"),
14914
+ useFactory: /* @__PURE__ */ __name((config) => {
14915
+ return createPinoLogger({
14916
+ level: "trace",
14917
+ filePath: `${config.logDir}/app.log`
14918
+ });
14919
+ }, "useFactory"),
14974
14920
  inject: [
14975
14921
  logger_config_default.KEY
14976
14922
  ]
14977
14923
  },
14978
14924
  {
14979
14925
  provide: TRACE_LOGGER,
14980
- useFactory: /* @__PURE__ */ __name((requestContext) => new PinoLoggerService(createPinoLogger({
14926
+ useFactory: /* @__PURE__ */ __name((requestContext, config) => new PinoLoggerService(createPinoLogger({
14981
14927
  level: "trace",
14982
- destinations: [
14983
- {
14984
- type: "file",
14985
- path: "logs/trace.log",
14986
- level: "trace"
14987
- }
14988
- ]
14928
+ filePath: `${config.logDir}/trace.log`
14989
14929
  }), requestContext), "useFactory"),
14990
14930
  inject: [
14991
- RequestContextService
14931
+ RequestContextService,
14932
+ logger_config_default.KEY
14992
14933
  ]
14993
14934
  },
14994
14935
  AppLogger,