lhisp-logger 3.1.5 → 3.1.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lhisp-logger",
3
- "version": "3.1.5",
3
+ "version": "3.1.7",
4
4
  "description": "",
5
5
  "main": "src/lhisp-logger",
6
6
  "types": "src/lhisp-logger.d.ts",
@@ -4,7 +4,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.deepSerializeAxiosErrors = deepSerializeAxiosErrors;
5
5
  const axiosErrorSerializer_1 = require("./axiosErrorSerializer");
6
6
  const isAxiosError_1 = require("./isAxiosError");
7
- const MAX_STRING_LENGTH = 128;
7
+ const DEFAULT_MAX_STRING_LENGTH = 128;
8
+ const ENV_MAX_STRING_LENGTH = Number(process.env.LOG_MAX_STRING_LENGTH);
9
+ const MAX_STRING_LENGTH = Number.isFinite(ENV_MAX_STRING_LENGTH) && ENV_MAX_STRING_LENGTH > 0
10
+ ? Math.floor(ENV_MAX_STRING_LENGTH)
11
+ : DEFAULT_MAX_STRING_LENGTH;
8
12
  function isProbablyBase64(value) {
9
13
  if (!value || value.length < 16 || value.length % 4 !== 0)
10
14
  return false;
@@ -71,12 +75,12 @@ function deepSerializeAxiosErrors(value, seen) {
71
75
  if (Array.isArray(value)) {
72
76
  return value.map((item) => deepSerializeAxiosErrors(item, localSeen));
73
77
  }
74
- // Keep non-plain objects (Date, Buffer, Error, etc.) untouched except axios errors above
75
- const proto = Object.getPrototypeOf(obj);
76
- const isPlain = proto === Object.prototype || proto === null;
77
- if (!isPlain) {
78
+ // Keep binary/typed payloads untouched to avoid exploding into index keys.
79
+ if (Buffer.isBuffer(value) || ArrayBuffer.isView(value)) {
78
80
  return value;
79
81
  }
82
+ // Traverse enumerable keys for both plain objects and class instances
83
+ // (e.g. class-validator ValidationError), so nested large strings are truncated.
80
84
  const out = {};
81
85
  for (const [k, v] of Object.entries(value)) {
82
86
  out[k] = deepSerializeAxiosErrors(v, localSeen);
@@ -73,6 +73,10 @@ if (lokiEnabled) {
73
73
  }
74
74
  const name = process.env.LOG_NAME || undefined;
75
75
  const transport = pino_1.default.transport({ targets });
76
+ const serializeError = (error) => {
77
+ const base = (0, isAxiosError_1.isAxiosError)(error) ? (0, axiosErrorSerializer_1.axiosErrorSerializer)(error) : pino_1.default.stdSerializers.err(error);
78
+ return (0, deepSerializeAxiosErrors_1.deepSerializeAxiosErrors)(base);
79
+ };
76
80
  const logger = (0, pino_1.default)({
77
81
  name: appName,
78
82
  level,
@@ -83,8 +87,8 @@ const logger = (0, pino_1.default)({
83
87
  },
84
88
  },
85
89
  serializers: {
86
- err: (error) => ((0, isAxiosError_1.isAxiosError)(error) ? (0, axiosErrorSerializer_1.axiosErrorSerializer)(error) : pino_1.default.stdSerializers.err(error)),
87
- error: (error) => ((0, isAxiosError_1.isAxiosError)(error) ? (0, axiosErrorSerializer_1.axiosErrorSerializer)(error) : pino_1.default.stdSerializers.err(error)),
90
+ err: serializeError,
91
+ error: serializeError,
88
92
  axiosError: axiosErrorSerializer_1.axiosErrorSerializer,
89
93
  },
90
94
  formatters: {