adicionado integração com loki

This commit is contained in:
Luiz Silva 2025-02-21 14:37:06 -03:00
parent 745c04819b
commit 3c8aa13a5e
14 changed files with 202 additions and 7 deletions

1
dist/index.d.ts vendored
View file

@ -8,3 +8,4 @@ export * from "./ecosistema";
export * from "./variaveisComuns";
export * from "./tipagemRotas";
export * from "./extensoes";
export * from "./logger";

1
dist/index.js vendored
View file

@ -24,4 +24,5 @@ __exportStar(require("./ecosistema"), exports);
__exportStar(require("./variaveisComuns"), exports);
__exportStar(require("./tipagemRotas"), exports);
__exportStar(require("./extensoes"), exports);
__exportStar(require("./logger"), exports);
//# sourceMappingURL=index.js.map

2
dist/index.js.map vendored
View file

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,6CAA0B;AAC1B,8CAA2B;AAC3B,gDAA6B;AAC7B,oDAAiC;AACjC,yCAAsB;AACtB,+CAA4B;AAC5B,oDAAiC;AACjC,iDAA8B;AAC9B,8CAA2B"}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,6CAA0B;AAC1B,8CAA2B;AAC3B,gDAA6B;AAC7B,oDAAiC;AACjC,yCAAsB;AACtB,+CAA4B;AAC5B,oDAAiC;AACjC,iDAA8B;AAC9B,8CAA2B;AAC3B,2CAAwB"}

15
dist/logger.d.ts vendored Normal file
View file

@ -0,0 +1,15 @@
interface LogOptions {
app?: string;
conta?: string;
usuario?: string;
detalhes?: unknown[];
}
export declare const logger: {
/** 🟢 Informação geral */
info: (message: string, options?: LogOptions) => Promise<void>;
/** 🟡 Aviso/atenção necessária */
warn: (message: string, options?: LogOptions) => Promise<void>;
/** 🔴 Erro crítico na execução */
error: (message: string, options?: LogOptions) => Promise<void>;
};
export {};

51
dist/logger.js vendored Normal file
View file

@ -0,0 +1,51 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.logger = void 0;
const cross_fetch_1 = __importDefault(require("cross-fetch"));
const LOKI_BASE_URL = "https://log.idz.one";
const LOKI_ENDPOINT = "/loki/api/v1/push";
const createLogger = (level) => {
const sendToLoki = async (message, options = {}) => {
const { app, conta, usuario, detalhes = [] } = options;
const timestamp = `${Date.now()}000000`;
try {
// Formata a linha de log principal
const mainLog = detalhes.length > 0
? `${message} | ${detalhes.map((d) => JSON.stringify(d)).join(" ")}`
: message;
const payload = {
stream: { app, conta, usuario, level },
values: [
[
timestamp,
mainLog, // Linha de log direta
],
],
};
const response = await (0, cross_fetch_1.default)(`${LOKI_BASE_URL}${LOKI_ENDPOINT}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ streams: [payload] }),
});
if (!response.ok) {
throw new Error(`Erro ${response.status}: ${await response.text()}`);
}
}
catch (error) {
console.error("[Logger] Falha no envio:", error);
}
};
return sendToLoki;
};
exports.logger = {
/** 🟢 Informação geral */
info: createLogger("info"),
/** 🟡 Aviso/atenção necessária */
warn: createLogger("warn"),
/** 🔴 Erro crítico na execução */
error: createLogger("error"),
};
//# sourceMappingURL=logger.js.map

1
dist/logger.js.map vendored Normal file
View file

@ -0,0 +1 @@
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAoC;AAEpC,MAAM,aAAa,GAAG,qBAAqB,CAAA;AAC3C,MAAM,aAAa,GAAG,mBAAmB,CAAA;AAqBzC,MAAM,YAAY,GAAG,CAAC,KAAe,EAAE,EAAE;IACvC,MAAM,UAAU,GAAG,KAAK,EAAE,OAAe,EAAE,UAAsB,EAAE,EAAE,EAAE;QACrE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,GAAG,EAAE,EAAE,GAAG,OAAO,CAAA;QACtD,MAAM,SAAS,GAA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AAkC;IAClC,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC;IAC1B,kCAAkC;IAClC,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC;CAC7B,CAAA"}

1
dist/teste.d.ts vendored Normal file
View file

@ -0,0 +1 @@
export {};

5
dist/teste.js vendored Normal file
View file

@ -0,0 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const logger_1 = require("./logger");
logger_1.logger.error("Esse é um erro", { app: "teste" });
//# sourceMappingURL=teste.js.map

1
dist/teste.js.map vendored Normal file
View file

@ -0,0 +1 @@
{"version":3,"file":"teste.js","sourceRoot":"","sources":["../src/teste.ts"],"names":[],"mappings":";;AAAA,qCAAiC;AAEjC,eAAM,CAAC,KAAK,CAAC,gBAAgB,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAA"}