diff --git a/src/logger.ts b/src/logger.ts index 2bf9803..01d7672 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -40,50 +40,49 @@ type tipoLog = { } export const logger = - ({ app, eProducao }: { app: string; eProducao: boolean }) => - ({ inquilino, usuario }: tipoOpSessao) => - async ( - level: tipoLevel, - mensagem: string, - op_tipoLog?: tipoLog, - ): Promise<[objeto: object, erro?: string]> => { - let { __filename, detalhes, local } = op_tipoLog || {} + ({ app: app_e, eProducao }: { app: string; eProducao: boolean }) => + ({ inquilino, usuario }: tipoOpSessao) => + async ( + level: tipoLevel, + mensagem: string, + op_tipoLog?: tipoLog, + ): Promise<[objeto: object, erro?: string]> => { + let { __filename, detalhes, local } = op_tipoLog || {} - if (!eProducao) { - app = `DEV-${app}` - } + const app = `${eProducao ? '' : 'DEV-'}${app_e}` - if (cwd && __filename) { - __filename = __filename.replace(cwd, "") - } - if (local) { - detalhes = [`${nomeVariavel({ local })}="${local}"`] - } + if (cwd && __filename) { + __filename = __filename.replace(cwd, "") + } - if (__filename) { - detalhes = [`${nomeVariavel({ __filename })}="${__filename}"`] - } + if (local) { + detalhes = [`${nomeVariavel({ local })}="${local}"`] + } - const timestamp = `${Date.now()}000000` + if (__filename) { + detalhes = [`${nomeVariavel({ __filename })}="${__filename}"`] + } - const mainLog = detalhes?.length - ? `${mensagem} | ${detalhes.map((d) => JSON.stringify(d)).join(" ")}` - : mensagem + const timestamp = `${Date.now()}000000` - const payload = { - stream: { app, inquilino, usuario, level }, - values: [ - [ - timestamp, - mainLog, // Linha de log direta - ], - ], - } + const mainLog = detalhes?.length + ? `${mensagem} | ${detalhes.map((d) => JSON.stringify(d)).join(" ")}` + : mensagem - const objeto = { streams: [payload] } + const payload = { + stream: { app, inquilino, usuario, level }, + values: [ + [ + timestamp, + mainLog, // Linha de log direta + ], + ], + } - const response = await postLogger({ objeto }) + const objeto = { streams: [payload] } - return response - } + const response = await postLogger({ objeto }) + + return response + }