adicionado integração com loki
This commit is contained in:
parent
745c04819b
commit
3c8aa13a5e
14 changed files with 202 additions and 7 deletions
51
dist/logger.js
vendored
Normal file
51
dist/logger.js
vendored
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.logger = void 0;
|
||||
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
||||
const LOKI_BASE_URL = "https://log.idz.one";
|
||||
const LOKI_ENDPOINT = "/loki/api/v1/push";
|
||||
const createLogger = (level) => {
|
||||
const sendToLoki = async (message, options = {}) => {
|
||||
const { app, conta, usuario, detalhes = [] } = options;
|
||||
const timestamp = `${Date.now()}000000`;
|
||||
try {
|
||||
// Formata a linha de log principal
|
||||
const mainLog = detalhes.length > 0
|
||||
? `${message} | ${detalhes.map((d) => JSON.stringify(d)).join(" ")}`
|
||||
: message;
|
||||
const payload = {
|
||||
stream: { app, conta, usuario, level },
|
||||
values: [
|
||||
[
|
||||
timestamp,
|
||||
mainLog, // Linha de log direta
|
||||
],
|
||||
],
|
||||
};
|
||||
const response = await (0, cross_fetch_1.default)(`${LOKI_BASE_URL}${LOKI_ENDPOINT}`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ streams: [payload] }),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`Erro ${response.status}: ${await response.text()}`);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error("[Logger] Falha no envio:", error);
|
||||
}
|
||||
};
|
||||
return sendToLoki;
|
||||
};
|
||||
exports.logger = {
|
||||
/** 🟢 Informação geral */
|
||||
info: createLogger("info"),
|
||||
/** 🟡 Aviso/atenção necessária */
|
||||
warn: createLogger("warn"),
|
||||
/** 🔴 Erro crítico na execução */
|
||||
error: createLogger("error"),
|
||||
};
|
||||
//# sourceMappingURL=logger.js.map
|
||||
Loading…
Add table
Add a link
Reference in a new issue