lhisp-logger 2.2.3 → 2.2.5

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": "2.2.3",
3
+ "version": "2.2.5",
4
4
  "description": "",
5
5
  "main": "src/lhisp-logger",
6
6
  "types": "src/lhisp-logger.d.ts",
@@ -12,6 +12,7 @@ export interface LhLoggerOptions {
12
12
  lokiEnabled?: boolean;
13
13
  lokiUrl?: string;
14
14
  labels?: Record<string, string>;
15
+ propsToLabels?: string[];
15
16
  }
16
17
  export declare function lhLogger(options?: LhLoggerOptions): Logger;
17
18
  export default lhLogger;
@@ -42,6 +42,12 @@ function lhLogger(options = {}) {
42
42
  error: (error) => ((0, isAxiosError_1.isAxiosError)(error) ? (0, axiosErrorSerializer_1.axiosErrorSerializer)(error) : pino_1.default.stdSerializers.err(error)),
43
43
  axiosError: axiosErrorSerializer_1.axiosErrorSerializer,
44
44
  },
45
+ formatters: {
46
+ // Ensure axios errors anywhere in the log object are serialized
47
+ log: (obj) => {
48
+ return deepSerializeAxiosErrors(obj);
49
+ },
50
+ },
45
51
  };
46
52
  const targets = [];
47
53
  if (pretty) {
@@ -64,6 +70,7 @@ function lhLogger(options = {}) {
64
70
  options: {
65
71
  host: lokiUrl,
66
72
  labels: Object.assign({ app: appName, env: process.env.NODE_ENV || "development", servidor: process.env.SERVERTAG || getEtcHostname() || os_1.default.hostname() }, options.labels),
73
+ propsToLabels: ["dbname", "traceId", ...(options.propsToLabels || [])],
67
74
  interval: 5,
68
75
  batching: true,
69
76
  },
@@ -92,3 +99,34 @@ function lhLogger(options = {}) {
92
99
  : pino_1.default.destination(1));
93
100
  }
94
101
  exports.default = lhLogger;
102
+ // Recursively serialize any axios error present in the provided value.
103
+ // Handles arrays, plain objects, and protects against circular structures.
104
+ function deepSerializeAxiosErrors(value, seen) {
105
+ if (typeof value !== "object")
106
+ return value;
107
+ // axios errors have a distinctive shape; use isAxiosError to detect
108
+ if ((0, isAxiosError_1.isAxiosError)(value)) {
109
+ return (0, axiosErrorSerializer_1.axiosErrorSerializer)(value);
110
+ }
111
+ const obj = value;
112
+ const localSeen = seen || new WeakSet();
113
+ if (localSeen.has(obj)) {
114
+ // Avoid infinite recursion on circular structures
115
+ return "[Circular]";
116
+ }
117
+ localSeen.add(obj);
118
+ if (Array.isArray(value)) {
119
+ return value.map((item) => deepSerializeAxiosErrors(item, localSeen));
120
+ }
121
+ // Keep non-plain objects (Date, Buffer, Error, etc.) untouched except axios errors above
122
+ const proto = Object.getPrototypeOf(obj);
123
+ const isPlain = proto === Object.prototype || proto === null;
124
+ if (!isPlain) {
125
+ return value;
126
+ }
127
+ const out = {};
128
+ for (const [k, v] of Object.entries(value)) {
129
+ out[k] = deepSerializeAxiosErrors(v, localSeen);
130
+ }
131
+ return out;
132
+ }