lhisp-logger 2.1.0 → 2.2.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 +1 -1
- package/src/lhisp-logger.js +27 -1
package/package.json
CHANGED
package/src/lhisp-logger.js
CHANGED
|
@@ -4,9 +4,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.lhLogger = lhLogger;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const os_1 = __importDefault(require("os"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
7
10
|
const pino_1 = __importDefault(require("pino"));
|
|
8
11
|
const axiosErrorSerializer_1 = require("./axiosErrorSerializer");
|
|
9
12
|
const isAxiosError_1 = require("./isAxiosError");
|
|
13
|
+
function getHostPackageName() {
|
|
14
|
+
try {
|
|
15
|
+
const pkgPath = path_1.default.resolve(process.cwd(), "package.json");
|
|
16
|
+
const content = fs_1.default.readFileSync(pkgPath, "utf8");
|
|
17
|
+
const pkg = JSON.parse(content);
|
|
18
|
+
return typeof (pkg === null || pkg === void 0 ? void 0 : pkg.name) === "string" ? pkg.name : undefined;
|
|
19
|
+
}
|
|
20
|
+
catch (_a) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function getEtcHostname() {
|
|
25
|
+
try {
|
|
26
|
+
const content = fs_1.default.readFileSync("/etc/hostname", "utf8");
|
|
27
|
+
const host = content.trim();
|
|
28
|
+
return host ? host : undefined;
|
|
29
|
+
}
|
|
30
|
+
catch (_a) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
10
34
|
function lhLogger(options = {}) {
|
|
11
35
|
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
36
|
`${process.env.LOG_LOKI_PROTOCOL || "http"}://${process.env.LOG_LOKI_HOST || "logs.lhprovedor.com.br"}:${process.env.LOG_LOKI_PORT || "3100"}`, } = options;
|
|
@@ -33,9 +57,11 @@ function lhLogger(options = {}) {
|
|
|
33
57
|
});
|
|
34
58
|
}
|
|
35
59
|
if (lokiEnabled) {
|
|
60
|
+
const appName = getHostPackageName() || name || process.env.npm_package_name || "lhisp-app";
|
|
36
61
|
const labels = {
|
|
37
|
-
app:
|
|
62
|
+
app: appName,
|
|
38
63
|
env: process.env.NODE_ENV || "development",
|
|
64
|
+
servidor: process.env.SERVERTAG || getEtcHostname() || os_1.default.hostname(),
|
|
39
65
|
};
|
|
40
66
|
targets.push({
|
|
41
67
|
level,
|