melhorias em logger
This commit is contained in:
parent
36d3cc6aa4
commit
79a83fe158
8 changed files with 79 additions and 97 deletions
73
dist/logger.js
vendored
73
dist/logger.js
vendored
|
|
@ -8,48 +8,41 @@ const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|||
const variaveisComuns_1 = require("./variaveisComuns");
|
||||
const LOKI_BASE_URL = "https://log.idz.one";
|
||||
const LOKI_ENDPOINT = "/loki/api/v1/push";
|
||||
const logger = ({ app, eProducao }) => ({ inquilino, usuario }) => {
|
||||
const f = (level) => async (mensagem, op_tipoLog) => {
|
||||
let { __filename, detalhes, local } = op_tipoLog || {};
|
||||
if (!eProducao) {
|
||||
app = `DEV-${app}`;
|
||||
}
|
||||
if (__filename && typeof process != "undefined" && process.cwd()) {
|
||||
__filename = __filename.replace(process.cwd(), "");
|
||||
}
|
||||
if (local) {
|
||||
detalhes = [`${(0, variaveisComuns_1.nomeVariavel)({ local })}="${local}"`];
|
||||
}
|
||||
if (__filename) {
|
||||
detalhes = [`${(0, variaveisComuns_1.nomeVariavel)({ __filename })}="${__filename}"`];
|
||||
}
|
||||
const timestamp = `${Date.now()}000000`;
|
||||
const mainLog = detalhes?.length
|
||||
? `${mensagem} | ${detalhes.map((d) => JSON.stringify(d)).join(" ")}`
|
||||
: mensagem;
|
||||
const payload = {
|
||||
stream: { app, inquilino, usuario, level },
|
||||
values: [
|
||||
[
|
||||
timestamp,
|
||||
mainLog, // Linha de log direta
|
||||
],
|
||||
const logger = ({ app, eProducao }) => ({ inquilino, usuario }) => async (level, mensagem, op_tipoLog) => {
|
||||
let { __filename, detalhes, local } = op_tipoLog || {};
|
||||
if (!eProducao) {
|
||||
app = `DEV-${app}`;
|
||||
}
|
||||
if (__filename && typeof process != "undefined" && process.cwd()) {
|
||||
__filename = __filename.replace(process.cwd(), "");
|
||||
}
|
||||
if (local) {
|
||||
detalhes = [`${(0, variaveisComuns_1.nomeVariavel)({ local })}="${local}"`];
|
||||
}
|
||||
if (__filename) {
|
||||
detalhes = [`${(0, variaveisComuns_1.nomeVariavel)({ __filename })}="${__filename}"`];
|
||||
}
|
||||
const timestamp = `${Date.now()}000000`;
|
||||
const mainLog = detalhes?.length
|
||||
? `${mensagem} | ${detalhes.map((d) => JSON.stringify(d)).join(" ")}`
|
||||
: mensagem;
|
||||
const payload = {
|
||||
stream: { app, inquilino, 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()}`);
|
||||
}
|
||||
};
|
||||
return {
|
||||
info: f("info"),
|
||||
warn: f("warn"),
|
||||
error: f("error"),
|
||||
],
|
||||
};
|
||||
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()}`);
|
||||
}
|
||||
};
|
||||
exports.logger = logger;
|
||||
//# sourceMappingURL=logger.js.map
|
||||
Loading…
Add table
Add a link
Reference in a new issue