From 235c7c1ef406e871de689a02a81029133ceed331 Mon Sep 17 00:00:00 2001 From: Lars Hampe Date: Tue, 12 Nov 2024 23:08:44 +0100 Subject: [PATCH] feat(logger): get service name via env var, hide logs on tests --- packages/logger/src/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/logger/src/index.ts b/packages/logger/src/index.ts index 09f774c..2f25158 100644 --- a/packages/logger/src/index.ts +++ b/packages/logger/src/index.ts @@ -15,6 +15,7 @@ export const logger = createLogger({ ), transports: [ new transports.Console({ + silent: import.meta.env.NODE_ENV === 'test', format: format.combine( format.colorize({ all: true }), format.padLevels(), @@ -32,9 +33,10 @@ export const logger = createLogger({ ), }), new LokiTransport({ + silent: import.meta.env.NODE_ENV === 'test', host: 'http://localhost:9100', json: true, - labels: { service: 'api' }, + labels: { service: import.meta.env.SERVICE_NAME ?? 'unknown' }, format: format.json(), replaceTimestamp: true, onConnectionError: (err) => console.error(err),