adicionado tipagem loki
This commit is contained in:
parent
1350348900
commit
25b760a2ff
4 changed files with 27 additions and 9 deletions
|
|
@ -3,10 +3,20 @@ import { nomeVariavel } from "./variaveisComuns"
|
|||
|
||||
const LOKI_BASE_URL = "https://log.idz.one"
|
||||
const LOKI_ENDPOINT = "/loki/api/v1/push"
|
||||
export type tipoLokiObjeto = {
|
||||
streams: {
|
||||
stream: {
|
||||
[k: string]: string
|
||||
}
|
||||
values: [string, string][]
|
||||
}[]
|
||||
}
|
||||
|
||||
export const postLogger = async ({
|
||||
objeto,
|
||||
}: { objeto: any }): Promise<[objeto: any, erro?: string]> => {
|
||||
}: { objeto: tipoLokiObjeto }): Promise<
|
||||
[objeto: tipoLokiObjeto, erro?: string]
|
||||
> => {
|
||||
const response = await crossFetch(`${LOKI_BASE_URL}${LOKI_ENDPOINT}`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
|
|
@ -56,7 +66,7 @@ export const logger =
|
|||
level: tipoLevel,
|
||||
mensagem: string,
|
||||
op_tipoLog?: tipoLog,
|
||||
): Promise<[objeto: object, erro?: string]> => {
|
||||
): Promise<[objeto: tipoLokiObjeto, erro?: string]> => {
|
||||
let {
|
||||
__filename,
|
||||
detalhes,
|
||||
|
|
@ -84,7 +94,7 @@ export const logger =
|
|||
? `${mensagem} | ${detalhes.map((d) => JSON.stringify(d)).join(" ")}`
|
||||
: mensagem
|
||||
|
||||
const payload = {
|
||||
const payload: tipoLokiObjeto["streams"][number] = {
|
||||
stream: {
|
||||
app,
|
||||
inquilino,
|
||||
|
|
@ -102,7 +112,7 @@ export const logger =
|
|||
],
|
||||
}
|
||||
|
||||
const objeto = { streams: [payload] }
|
||||
const objeto: tipoLokiObjeto = { streams: [payload] }
|
||||
|
||||
const response = await postLogger({ objeto })
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue