From 0be5faa0045285c147a7747aa9f302a69068b593 Mon Sep 17 00:00:00 2001 From: crisog Date: Tue, 10 Jan 2023 11:46:41 -0400 Subject: [PATCH] fix: only prod/staging loki --- src/services/logger.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/services/logger.ts b/src/services/logger.ts index aedfdfcc..7f54df13 100644 --- a/src/services/logger.ts +++ b/src/services/logger.ts @@ -7,6 +7,7 @@ require('dotenv').config() const { createLogger, format, transports: winstonTransports } = require('winston') const LokiWinston = require('winston-loki') +const environment = process.env.NODE_ENV || 'production' const accessKeyID = process.env.AWS_ACCESS_KEY_ID || '' const awsSecretAccessKey = process.env.AWS_SECRET_ACCESS_KEY || '' const region = process.env.REGION || '' @@ -68,12 +69,18 @@ const options = { const getTransports = () => { const transports = [new winstonTransports.Console(options.console)] - if (logToLoki) { - if (!lokiHost) { - throw new HttpErrors.InternalServerError('LOKI_HOST required in ENV') - } + if (environment === 'production' || environment === 'staging') { + if (logToLoki) { + if (!lokiHost) { + throw new HttpErrors.InternalServerError('LOKI_HOST required in ENV') + } + + if (!region) { + throw new HttpErrors.InternalServerError('REGION required in ENV') + } - transports.push(new LokiWinston(options.loki)) + transports.push(new LokiWinston(options.loki)) + } } return transports