feat(logger): get service name via env var, hide logs on tests
All checks were successful
Build and Push Docker Image / tests (push) Successful in 1m4s
Build and Push Docker Image / build (push) Successful in 4m15s

This commit is contained in:
Lars Hampe 2024-11-12 23:08:44 +01:00
parent 0d0c4c8469
commit 235c7c1ef4

View File

@ -15,6 +15,7 @@ export const logger = createLogger({
), ),
transports: [ transports: [
new transports.Console({ new transports.Console({
silent: import.meta.env.NODE_ENV === 'test',
format: format.combine( format: format.combine(
format.colorize({ all: true }), format.colorize({ all: true }),
format.padLevels(), format.padLevels(),
@ -32,9 +33,10 @@ export const logger = createLogger({
), ),
}), }),
new LokiTransport({ new LokiTransport({
silent: import.meta.env.NODE_ENV === 'test',
host: 'http://localhost:9100', host: 'http://localhost:9100',
json: true, json: true,
labels: { service: 'api' }, labels: { service: import.meta.env.SERVICE_NAME ?? 'unknown' },
format: format.json(), format: format.json(),
replaceTimestamp: true, replaceTimestamp: true,
onConnectionError: (err) => console.error(err), onConnectionError: (err) => console.error(err),