lhisp-logger 2.0.0 → 2.1.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/package.json +2 -1
- package/src/lhisp-logger.d.ts +2 -0
- package/src/lhisp-logger.js +38 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lhisp-logger",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/lhisp-logger",
|
|
6
6
|
"types": "src/lhisp-logger.d.ts",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"pino": "^10.1.0",
|
|
29
|
+
"pino-loki": "^3.0.0",
|
|
29
30
|
"pino-pretty": "^13.1.3"
|
|
30
31
|
}
|
|
31
32
|
}
|
package/src/lhisp-logger.d.ts
CHANGED
package/src/lhisp-logger.js
CHANGED
|
@@ -8,7 +8,8 @@ const pino_1 = __importDefault(require("pino"));
|
|
|
8
8
|
const axiosErrorSerializer_1 = require("./axiosErrorSerializer");
|
|
9
9
|
const isAxiosError_1 = require("./isAxiosError");
|
|
10
10
|
function lhLogger(options = {}) {
|
|
11
|
-
const { name = process.env.LOG_NAME || undefined, level = process.env.LOG_LEVEL || "info", destination = process.env.LOG_DESTINATION, sync = !!process.env.LOG_SYNC, pretty = true, colorize = true, ignore = "pid,hostname", translateTime = "yyyy-mm-dd HH:MM:ss", singleLine = true,
|
|
11
|
+
const { name = process.env.LOG_NAME || undefined, level = process.env.LOG_LEVEL || "info", destination = process.env.LOG_DESTINATION, sync = !!process.env.LOG_SYNC, pretty = true, colorize = true, ignore = "pid,hostname", translateTime = "yyyy-mm-dd HH:MM:ss", singleLine = true, lokiEnabled = (process.env.LOG_LOKI_ENABLED || "true").toLowerCase() !== "false", lokiUrl = process.env.LOG_LOKI_URL ||
|
|
12
|
+
`${process.env.LOG_LOKI_PROTOCOL || "http"}://${process.env.LOG_LOKI_HOST || "logs.lhprovedor.com.br"}:${process.env.LOG_LOKI_PORT || "3100"}`, } = options;
|
|
12
13
|
const baseConfig = {
|
|
13
14
|
name,
|
|
14
15
|
level,
|
|
@@ -18,8 +19,10 @@ function lhLogger(options = {}) {
|
|
|
18
19
|
axiosError: axiosErrorSerializer_1.axiosErrorSerializer,
|
|
19
20
|
},
|
|
20
21
|
};
|
|
22
|
+
const targets = [];
|
|
21
23
|
if (pretty) {
|
|
22
|
-
|
|
24
|
+
targets.push({
|
|
25
|
+
level,
|
|
23
26
|
target: "pino-pretty",
|
|
24
27
|
options: {
|
|
25
28
|
colorize,
|
|
@@ -27,13 +30,42 @@ function lhLogger(options = {}) {
|
|
|
27
30
|
translateTime,
|
|
28
31
|
singleLine,
|
|
29
32
|
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (lokiEnabled) {
|
|
36
|
+
const labels = {
|
|
37
|
+
app: name || process.env.npm_package_name || "lhisp-app",
|
|
38
|
+
env: process.env.NODE_ENV || "development",
|
|
30
39
|
};
|
|
40
|
+
targets.push({
|
|
41
|
+
level,
|
|
42
|
+
target: "pino-loki",
|
|
43
|
+
options: {
|
|
44
|
+
host: lokiUrl,
|
|
45
|
+
labels,
|
|
46
|
+
interval: 5,
|
|
47
|
+
batching: true,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (destination) {
|
|
52
|
+
targets.push({
|
|
53
|
+
level,
|
|
54
|
+
target: "pino/file",
|
|
55
|
+
options: {
|
|
56
|
+
destination,
|
|
57
|
+
mkdir: true,
|
|
58
|
+
append: true,
|
|
59
|
+
sync,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (targets.length) {
|
|
64
|
+
const transport = pino_1.default.transport({ targets });
|
|
65
|
+
return (0, pino_1.default)(baseConfig, transport);
|
|
31
66
|
}
|
|
32
67
|
return (0, pino_1.default)(baseConfig, destination
|
|
33
|
-
? pino_1.default.destination({
|
|
34
|
-
dest: destination,
|
|
35
|
-
sync,
|
|
36
|
-
})
|
|
68
|
+
? pino_1.default.destination({ dest: destination, sync })
|
|
37
69
|
: sync
|
|
38
70
|
? pino_1.default.destination({ sync: true })
|
|
39
71
|
: pino_1.default.destination(1));
|