build
This commit is contained in:
parent
aa7953e452
commit
f8dabeb40c
75 changed files with 712 additions and 57 deletions
69
dist-require/logger.js
Normal file
69
dist-require/logger.js
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.logger = exports.defineCwd = exports.postLogger = void 0;
|
||||
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 postLogger = async ({ objeto, }) => {
|
||||
const response = await (0, cross_fetch_1.default)(`${LOKI_BASE_URL}${LOKI_ENDPOINT}`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(objeto),
|
||||
}).catch((a) => a);
|
||||
if (!response.ok) {
|
||||
return [objeto, `Erro ${response.status}: ${await response?.text?.()}`];
|
||||
}
|
||||
return [objeto];
|
||||
};
|
||||
exports.postLogger = postLogger;
|
||||
let cwd = "";
|
||||
/** define a localização da pasta do projeto */
|
||||
const defineCwd = (novoCwd) => {
|
||||
cwd = novoCwd;
|
||||
};
|
||||
exports.defineCwd = defineCwd;
|
||||
const logger = ({ app: app_e, eProducao, parametros: parametrosAmbiente }) => ({ inquilino, usuario, parametros: parametrosSessao }) => async (level, mensagem, op_tipoLog) => {
|
||||
let { __filename, detalhes, local, parametros: parametrosLog, } = op_tipoLog || {};
|
||||
const app = `${eProducao ? "" : "DEV-"}${app_e}`;
|
||||
if (cwd && __filename) {
|
||||
__filename = __filename.replace(cwd, "");
|
||||
}
|
||||
if (local) {
|
||||
detalhes = [`${(0, variaveisComuns_1.nomeVariavel)({ local })}="${local}"`, ...(detalhes || [])];
|
||||
}
|
||||
if (__filename) {
|
||||
detalhes = [
|
||||
`${(0, variaveisComuns_1.nomeVariavel)({ __filename })}="${__filename}"`,
|
||||
...(detalhes || []),
|
||||
];
|
||||
}
|
||||
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,
|
||||
...(parametrosAmbiente || {}),
|
||||
...(parametrosSessao || {}),
|
||||
...(parametrosLog || {}),
|
||||
},
|
||||
values: [
|
||||
[
|
||||
timestamp,
|
||||
mainLog, // Linha de log direta
|
||||
],
|
||||
],
|
||||
};
|
||||
const objeto = { streams: [payload] };
|
||||
const response = await (0, exports.postLogger)({ objeto });
|
||||
return response;
|
||||
};
|
||||
exports.logger = logger;
|
||||
Loading…
Add table
Add a link
Reference in a new issue