107 lines
No EOL
3.6 KiB
JavaScript
107 lines
No EOL
3.6 KiB
JavaScript
"use strict";
|
|
var __create = Object.create;
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __getProtoOf = Object.getPrototypeOf;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
// file that has been converted to a CommonJS file using a Babel-
|
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
mod
|
|
));
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
var logger_exports = {};
|
|
__export(logger_exports, {
|
|
defineCwd: () => defineCwd,
|
|
logger: () => logger,
|
|
postLogger: () => postLogger
|
|
});
|
|
module.exports = __toCommonJS(logger_exports);
|
|
var import_cross_fetch = __toESM(require("cross-fetch"));
|
|
var import_variaveisComuns = require("./variaveisComuns");
|
|
const LOKI_BASE_URL = "https://log.idz.one";
|
|
const LOKI_ENDPOINT = "/loki/api/v1/push";
|
|
const postLogger = async ({
|
|
objeto
|
|
}) => {
|
|
const response = await (0, import_cross_fetch.default)(`${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 = [`${(0, import_variaveisComuns.nomeVariavel)({ local })}="${local}"`, ...detalhes || []];
|
|
}
|
|
if (__filename) {
|
|
detalhes = [
|
|
`${(0, import_variaveisComuns.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;
|
|
};
|
|
// Annotate the CommonJS export names for ESM import in node:
|
|
0 && (module.exports = {
|
|
defineCwd,
|
|
logger,
|
|
postLogger
|
|
});
|
|
//# sourceMappingURL=logger.js.map
|