lhisp-logger 3.1.2 → 3.1.4
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
|
@@ -4,8 +4,27 @@ 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;
|
|
8
|
+
function isProbablyBase64(value) {
|
|
9
|
+
if (!value || value.length < 16 || value.length % 4 !== 0)
|
|
10
|
+
return false;
|
|
11
|
+
// Base64 strings should only contain valid chars and optional padding.
|
|
12
|
+
return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value);
|
|
13
|
+
}
|
|
14
|
+
function truncateString(value, maxLength) {
|
|
15
|
+
if (value.length <= maxLength)
|
|
16
|
+
return value;
|
|
17
|
+
const remaining = value.length - maxLength;
|
|
18
|
+
return `${value.slice(0, maxLength)}…[truncated ${remaining} chars]`;
|
|
19
|
+
}
|
|
7
20
|
// Handles arrays, plain objects, and protects against circular structures.
|
|
8
21
|
function deepSerializeAxiosErrors(value, seen) {
|
|
22
|
+
if (typeof value === "string") {
|
|
23
|
+
if (isProbablyBase64(value) || value.length > MAX_STRING_LENGTH) {
|
|
24
|
+
return truncateString(value, MAX_STRING_LENGTH);
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
9
28
|
// Guard against null which has typeof 'object' but is invalid for WeakSet
|
|
10
29
|
if (value === null || typeof value !== "object")
|
|
11
30
|
return value;
|
package/src/lhisp-logger.js
CHANGED
|
@@ -18,7 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
const fs_1 = __importDefault(require("fs"));
|
|
21
|
-
const os_1 = __importDefault(require("os"));
|
|
22
21
|
const pino_1 = __importDefault(require("pino"));
|
|
23
22
|
const axiosErrorSerializer_1 = require("./axiosErrorSerializer");
|
|
24
23
|
const deepSerializeAxiosErrors_1 = require("./deepSerializeAxiosErrors");
|
|
@@ -63,7 +62,7 @@ if (lokiEnabled) {
|
|
|
63
62
|
labels: {
|
|
64
63
|
app: appName,
|
|
65
64
|
env: process.env.NODE_ENV || "development",
|
|
66
|
-
servidor: process.env.SERVERTAG || getEtcHostname() ||
|
|
65
|
+
servidor: process.env.SERVERTAG || getEtcHostname() || "no-host-name",
|
|
67
66
|
},
|
|
68
67
|
propsToLabels: ["dbname", "traceId"],
|
|
69
68
|
batching: true, // 🔑
|
|
@@ -77,6 +76,12 @@ const transport = pino_1.default.transport({ targets });
|
|
|
77
76
|
const logger = (0, pino_1.default)({
|
|
78
77
|
name: appName,
|
|
79
78
|
level,
|
|
79
|
+
hooks: {
|
|
80
|
+
logMethod(args, method) {
|
|
81
|
+
const nextArgs = args.map((arg) => (0, deepSerializeAxiosErrors_1.deepSerializeAxiosErrors)(arg));
|
|
82
|
+
return method.apply(this, nextArgs);
|
|
83
|
+
},
|
|
84
|
+
},
|
|
80
85
|
serializers: {
|
|
81
86
|
err: (error) => ((0, isAxiosError_1.isAxiosError)(error) ? (0, axiosErrorSerializer_1.axiosErrorSerializer)(error) : pino_1.default.stdSerializers.err(error)),
|
|
82
87
|
error: (error) => ((0, isAxiosError_1.isAxiosError)(error) ? (0, axiosErrorSerializer_1.axiosErrorSerializer)(error) : pino_1.default.stdSerializers.err(error)),
|