melhorias em log

This commit is contained in:
Luiz Silva 2025-02-22 14:24:26 -03:00
parent e1d94a75bd
commit 505f64f70b
5 changed files with 39 additions and 21 deletions

View file

@ -4,6 +4,21 @@ import { nomeVariavel } from "./variaveisComuns"
const LOKI_BASE_URL = "https://log.idz.one"
const LOKI_ENDPOINT = "/loki/api/v1/push"
export const postLogger = async ({
objeto,
}: { objeto: any }): Promise<[objeto: any, erro?: string]> => {
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?.()}`]
} else {
return [objeto]
}
}
type tipoLevel = "info" | "warn" | "error"
type tipoOpSessao = {
@ -60,14 +75,7 @@ export const logger =
const objeto = { streams: [payload] }
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?.()}`]
}
const response = await postLogger({ objeto })
return [objeto]
return response
}