This commit is contained in:
Luiz Silva 2025-02-21 17:58:21 -03:00
parent decb819207
commit 36d3cc6aa4
5 changed files with 25 additions and 8 deletions

View file

@ -1,11 +1,12 @@
import crossFetch from "cross-fetch"
import { nomeVariavel } from "./variaveisComuns"
const LOKI_BASE_URL = "https://log.idz.one"
const LOKI_ENDPOINT = "/loki/api/v1/push"
type tipoLevel = "info" | "warn" | "error"
type tipoAmb = {
type tipoOpSessao = {
inquilino: string
usuario: string
}
@ -13,14 +14,15 @@ type tipoAmb = {
type tipoLog = {
detalhes?: unknown[]
__filename?: string
local?: string
}
export const logger =
({ app, eProducao }: { app: string; eProducao: boolean }) =>
({ inquilino, usuario }: tipoAmb) => {
({ inquilino, usuario }: tipoOpSessao) => {
const f =
(level: tipoLevel) => async (mensagem: string, op_tipoLog?: tipoLog) => {
let { __filename, detalhes } = op_tipoLog || {}
let { __filename, detalhes, local } = op_tipoLog || {}
if (!eProducao) {
app = `DEV-${app}`
@ -29,6 +31,13 @@ export const logger =
if (__filename && typeof process != "undefined" && process.cwd()) {
__filename = __filename.replace(process.cwd(), "")
}
if (local) {
detalhes = [`${nomeVariavel({ local })}="${local}"`]
}
if (__filename) {
detalhes = [`${nomeVariavel({ __filename })}="${__filename}"`]
}
const timestamp = `${Date.now()}000000`