melhorias tsup
This commit is contained in:
parent
8efeb59716
commit
40570d1b00
96 changed files with 621 additions and 107 deletions
71
dist-front/logger.js
Normal file
71
dist-front/logger.js
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import crossFetch from "cross-fetch";
|
||||
import { nomeVariavel } from "./variaveisComuns";
|
||||
const LOKI_BASE_URL = "https://log.idz.one";
|
||||
const LOKI_ENDPOINT = "/loki/api/v1/push";
|
||||
const postLogger = async ({
|
||||
objeto
|
||||
}) => {
|
||||
const response = await crossFetch(`${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];
|
||||
};
|
||||
let cwd = "";
|
||||
const defineCwd = (novoCwd) => {
|
||||
cwd = novoCwd;
|
||||
};
|
||||
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 = [`${nomeVariavel({ local })}="${local}"`, ...detalhes || []];
|
||||
}
|
||||
if (__filename) {
|
||||
detalhes = [
|
||||
`${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 postLogger({ objeto });
|
||||
return response;
|
||||
};
|
||||
export {
|
||||
defineCwd,
|
||||
logger,
|
||||
postLogger
|
||||
};
|
||||
//# sourceMappingURL=logger.js.map
|
||||
Loading…
Add table
Add a link
Reference in a new issue